开发者

check if webpage exists and see if it contains string in vb.net

开发者 https://www.devze.com 2022-12-15 22:43 出处:网络
I need to check if a webpage exists if it does whether a certain string exists anywhere on the page. Preferably I\'d like to do th开发者_StackOverflow中文版is without a webbrowser control, so that ima

I need to check if a webpage exists if it does whether a certain string exists anywhere on the page. Preferably I'd like to do th开发者_StackOverflow中文版is without a webbrowser control, so that images don't have to be downloaded and it doesn't have to be rendered.

So is there a way to do this?


First, follow the instructions here (Though, the instructions are in C#, they should easily be converted to 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();

Now, once you have this, perform the search on result string

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

精彩评论

暂无评论...
验证码 换一张
取 消