用DOM实现文章采集--采集到网页源码(7)
来源:未知 责任编辑:责任编辑 发表时间:2014-04-20 03:40 点击:次
responseStream.Close();
if (response != null)
response.Close();
}
return info;
}
#region 取得远程资源
/// <summary>
/// 取得远程资源 www.2cto.com
/// </summary>
/// <param name="strUrl">要取的URL</param>
/// <returns>网页源代码</returns>
public RemoteRes GetRemoteResource(string strUrl)
{
HttpWebResponse response = null;
Stream stream = null;
RemoteRes info = new RemoteRes();
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl);
request.AllowAutoRedirect = true;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)";
request.Referer = "http://" + new Uri(strUrl).Host;
response = request.GetResponse() as HttpWebResponse;
stream = response.GetResponseStream();
info.ContentType = response.ContentType;
MemoryStream ms = new MemoryStream();
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>