抓取网页遇到了问题!
刚开始用WebClient将指定网页下载下来,在本机运行正常,上传到服务器后正常运行了一段时间,但是后来在去访问的时候就怎么也运行不成功了返回错误:The operation has timed out ;为什么总是超时呢怎么处理呢?为什么前面运行是正常的呢,接着我又用HttpWebRequest想达到相同的目的但是怎么也抓取不完那个网页,只能取得一部分,这又应该如何解决呢?
下面是用HttpWebRequest的方法:
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.caotingna.com/item/webclient__229080.aspx");
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream st = myHttpWebResponse.GetResponseStream();
byte[] buf = new byte[myHttpWebResponse.ContentLength];
int count = st.Read(buf, 0, buf.Length);
Console.WriteLine(Encoding.UTF8.GetString(buf, 0, count));