.net 远程抓取页面信息

sdfasdf2w2 2012-04-10 05:02:57
代码如下:
static void MainFunction()
{
//http://www.windowsphone.com/zh-CN/games 首页-中国
//http://www.windowsphone.com/zh-CN/apps/7ead781c-50f1-43bc-be2c-0c604da39c98 详细页
//http://www.windowsphone.com/en-US/marketplace 首页-美国

string _URL = "http://www.windowsphone.com/zh-CN/games";
string _TestStr = SendDataByPost(_URL);
}
static string SendDataByPost(string Url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);

request.Method = "GET";
request.Host = "news.bjx.com.cn";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Headers[HttpRequestHeader.AcceptLanguage] = "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";
request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";

var property = typeof(WebHeaderCollection).GetProperty("InnerCollection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
if (property != null)
{
var collection = property.GetValue(request.Headers, null) as NameValueCollection;
collection["Connection"] = "Keep-Alive";
}

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();

return retString;
}
我要抓去以上三个页面的信息,以下是采集到的信息:
html><head><meta http-equiv="REFRESH" content="0; URL=http://www.windowsphone.com/zh-CN/apps/d56d814f-4fa8-410a-87c1-aea0cede6f87"><scripttype="text/javascript">function OnBack(){}</script></head>< ml>

不明白到底怎么回事,希望高手能给我解答一下:)
...全文
127 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
相当之稳重 2012-04-10
  • 打赏
  • 举报
回复
采集到的数据字符串 截取有问题。。

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧