Re: [問題] 請問抓取網頁原始碼有遺失現象

看板C_Sharp (C#)作者 (口白人生)時間18年前 (2007/09/12 17:40), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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
有讀書就知道StringBuilder的好
09/14 01:59, 1F
文章代碼(AID): #16vxGGxO (C_Sharp)
文章代碼(AID): #16vxGGxO (C_Sharp)