Re: [問題] 請問抓取網頁原始碼有遺失現象
※ 引述《liptonbin (wind)》之銘言:
: 請問我用HttpWebRequest HttpWebResponse
: 怎麼有些原始碼顯示不出來
: 就是網頁原始碼中間有缺 但是其中的中文英文都正常顯示"沒有亂碼"
: (只是會"少抓中間"的一些英文和中文字)
: 我哪邊寫錯了嗎? 我把Encoding.UTF8改成Encoding.ASCII或Encoding.Default都會少
: 謝謝
: 程式如下
: private void button4_Click(object sender, EventArgs e)
: {
: HttpWebRequest hwRequest = (HttpWebRequest)HttpWebRequest.Create(m_url.Text);
: HttpWebResponse hwResponse=(HttpWebResponse)hwRequest.GetResponse();
: System.IO.StreamReader sr = new
: System.IO.StreamReader(hwResponse.GetResponse\
: Stream(), Encoding.UTF8);
: int linen=0;
: string line="";
: line = sr.ReadLine();
: while (line != null)
: {
: textBox2.Text += line+'\r'+'\n';
: line = sr.ReadLine(); linen++;
: }
: }
要不要改用 WebClient 試試看呢! 然後記得幫他們加上 Header
ps. TextBox.Text 不適合拿來給你串接字串...
效率會非常非常差!!!
請先用 StringBuilder 串好再放進去
--
http://blog.roodo.com/chhuang
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.239.131
推
09/14 01:59, , 1F
09/14 01:59, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章
14
30