C#抓取网页内容的函数的代码
将写代码过程比较好的代码段备份一次,如下代码是关于C#抓取网页内容的函数的代码,应该能对大伙有较大用途。
private byte[] GetURLContents(string url)
{
var content = new MemoryStream();
var webReq = (HttpWebRequest)WebRequest.Create(url);
using (WebResponse response = webReq.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
responseStream.CopyTo(content);
}
}
return content.ToArray();
}