【问题标题】:check if webpage exists and see if it contains string in vb.net检查网站是否存在并查看它是否包含 vb.net 中的字符串
【发布时间】:2011-01-02 16:27:45
【问题描述】:

如果页面上的任何位置是否存在某个字符串,我需要检查网页是否存在。 最好我想在没有 webbrowser 控件的情况下执行此操作,这样就不必下载图像也不必渲染它。

那么有没有办法做到这一点?

【问题讨论】:

    标签: vb.net string webpage contains exists


    【解决方案1】:

    首先,按照here的说明进行操作(虽然说明是用C#编写的,但应该很容易转换成VB。)

    using System.Text; 
    using System.Net;
    using System.IO;
    
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
    myRequest.Method = "GET";
    WebResponse myResponse = myRequest.GetResponse();
    StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
    string result = sr.ReadToEnd();
    sr.Close();
    myResponse.Close();
    

    现在,一旦你有了这个,对结果字符串执行搜索

    Dim stringFound = result.IndexOf("My search string")
    

    【讨论】:

      猜你喜欢
      • 2015-10-11
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      • 2014-08-21
      • 2012-06-30
      • 1970-01-01
      相关资源
      最近更新 更多