你如何用C#搜索网站源代码?很难解释,继承人在python中做到这一点
import urllib2, re
word = "How to ask"
source = urllib2.urlopen("http://stackoverflow.com").read()
if re.search(word,source):
print "Found it "+word
Run Code Online (Sandbox Code Playgroud)
如果要从网页访问原始HTML,则需要执行以下操作:
所以代码如下:
string pageContent = null;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://example.com/page.html");
HttpWebResponse myres = (HttpWebResponse)myReq.GetResponse();
using (StreamReader sr = new StreamReader(myres.GetResponseStream()))
{
pageContent = sr.ReadToEnd();
}
if (pageContent.Contains("YourSearchWord"))
{
//Found It
}
Run Code Online (Sandbox Code Playgroud)