c#抓取別的網頁的內容
代码
string content = string.Empty;
string str = "http://www.baidu.com/";
WebRequest wrq = WebRequest.Create(str);
WebResponse wrs = wrq.GetResponse();
using (StreamReader dr = new StreamReader(wrs.GetResponseStream(), Encoding.GetEncoding("gb2312")))
{
content = dr.ReadToEnd();//这就是全部内容
//得到内容后根据正则获取你所需要的东西。要先分析他的html
}
using (StreamWriter sw = new StreamWriter(Server.MapPath("default.htm"), false, Encoding.GetEncoding("gb2312")))
{
sw.WriteLine(content);
}
}
string str = "http://www.baidu.com/";
WebRequest wrq = WebRequest.Create(str);
WebResponse wrs = wrq.GetResponse();
using (StreamReader dr = new StreamReader(wrs.GetResponseStream(), Encoding.GetEncoding("gb2312")))
{
content = dr.ReadToEnd();//这就是全部内容
//得到内容后根据正则获取你所需要的东西。要先分析他的html
}
using (StreamWriter sw = new StreamWriter(Server.MapPath("default.htm"), false, Encoding.GetEncoding("gb2312")))
{
sw.WriteLine(content);
}
}