作者VVll (J.)
看板C_Sharp
标题Re: [问题] 抓网页问题
时间Fri Oct 31 01:19:51 2014
你要不要考虑用webClient
有DownloadStringCompleted 的非同步下载方法
取出来就是string了
下载完成在去处理分析
分析完再回到下载流程
而且还可以挂proxy
※ 引述《fantoccini (如何实现儿时梦想)》之铭言:
: 小弟要去抓取股票的网页, 需要抓取一连串的网页
: 程式示意如下, 有个问题是, 程式在跑时网页并不会连续的被抓到
: (已排除网址错误问题)
: 例如说第一次有结果的是 company = 0,1,2,3,4,100,101,102,500
: 重跑一下可能是 0,2,3,4,5,6,7,88,400,...
: 进去debug, 会发现StreamReader 是没东西的(有时又会有)
: 请问这是甚麽样的原因 该如何解决
: for(int company = 0; company < company_list.Count; company++)
: {
: for (int year = cur_year; year >= cur_year - 1; year--)
: {
: for (int season = 1; season <= 4; season++)
: {
: StringBuilder sb = new StringBuilder();
: //下面的weburl 为简化而示意
: string weburl = "http://" + company + year + season;
: WebRequest myRequest = WebRequest.Create(weburl);
: myRequest.Method = "GET";
: WebResponse myResponse = myRequest.GetResponse();
: StreamReader sr = StreamReader(myResponse.GetRespon
: seStream(), Encoding.GetEncoding("big5"));
: string result = sr.ReadToEnd();
: sr.Close();
: myResponse.Close();
: }
: }
: }
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.240.236.58
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1414689595.A.D7E.html