public string GetPage(string strURL)
{
string strResult = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
strResult = sr.ReadToEnd();
sr.Close();
response.Close();
return strResult;
}
上面是采集网页时用到的核心代码
利用HttpWebRequest获取远程URL的内容,然后利用正则对想要的内容进行抓取。