zoukankan      html  css  js  c++  java
  • C#判断网页中是否含有某字符串

     

    简短的一段代码,可以判断webbrowser中打开的网页中是否含有某段字符串。这段代码比较有用,可以利用两个网页的不同之处来分辨出网页是否跳转到了需要的网页。

    代码如下:转载请注明出处:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace 判断网页中含有某个字符串
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                this.webBrowser1.Url = new Uri("http://www.baidu.com/");
            }

            private void button1_Click(object sender, EventArgs e)
            {
                string html = webBrowser1.Document.Body.OuterHtml;
                if (html.Contains("minxiangyangwfasg"))
                {
                    this.label1.Text = "存在此字符串";
                }
                else
                {
                    this.label1.Text = "不存在此字符串!";
                }
            }
        }
    }

  • 相关阅读:
    添加活动记录的小坑
    用windows的批处理文件批量更改文件后缀
    js日期的初始化的格式
    对象的继承
    关于换行字符的问题
    js获取dom对象style样式的值
    判断邮箱是否合法
    Python控制函数运行时间
    如何用python编写一个计时器的程序
    TF-IDF算法介绍及实现
  • 原文地址:https://www.cnblogs.com/minotmin/p/2699323.html
Copyright © 2011-2022 走看看