看板 C_Sharp 關於我們 聯絡資訊
你要不要考慮用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://www.ptt.cc/bbs/C_Sharp/M.1414689595.A.D7E.html