日期:2014-05-18  浏览次数:20371 次

做过新闻小偷程序的看看 ----为什么有的网页抓取不到源文件
做过新闻小偷程序的朋友都知道怎么“偷”新闻,比如
string   url= "http://www.sohu.com ";     //想要抓取的页面的地址
HttpWebRequest   webRequest   =   (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse   webResponse   =   (HttpWebResponse)webRequest.GetResponse();
Stream   stream   =   webResponse.GetResponseStream();
System.IO.StreamReader   streamReader   =   new   StreamReader(stream,   System.Text.Encoding.GetEncoding( "gb2312 "));
string   content   =   streamReader.ReadToEnd();
streamReader.Close();
webResponse.Close();
return   content;       //最后content就是该文件的源文件

可是我现在有个网址
http://panda.www.net.cn/cgi-bin/Check.cgi?domain1=111&domain=111&big5=n&sign=2&com=yes&cn=yes&comcn=yes&mobi=yes&image.x=29&image.y=6

这个中国万网的,为什么我抓取,最后得到的content是“请与万网联系”
他们这是用的什么反扒技术,而我的程序怎么改进才能得到我想要的源文件呢?

------解决方案--------------------
不喜欢新闻小偷,不过就这一问题而言

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
后加一行
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1) Web-Sniffer/1.0.24 ";