題:
請問vb.net如何抓取某網頁的內容?
2004-12-12 15:47:01 UTC
請問使用vb.net如何抓取某網頁的內容?我只知道vb6是使用inet control。請指教。謝謝
二 答案:
2004-12-13 16:30:14 UTC
請試試以下範例,我有測過,有問題再回應:



Imports System.Net

Imports System.Text

Imports System.IO



.....



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim req As WebRequest = WebRequest.Create("http://tw.stock.yahoo.com/")

Dim res As WebResponse = req.GetResponse()

Dim recS As Stream = res.GetResponseStream()

Dim enc As Encoding = System.Text.Encoding.GetEncoding("utf-8")

Dim sread As New StreamReader(recS, enc)

Dim s As String



s = ""

Dim read(256) As [Char]

Dim count As Integer = sread.Read(read, 0, 256)

Label1.Text = "receiving"

While count > 0

Dim str As New [String](read, 0, count)

Application.DoEvents()

s = s + str

count = sread.Read(read, 0, 256)

Label1.Text = Label1.Text + "."

End While

s = s + ControlChars.CrLf

sread.Close()

res.Close()

TextBox1.Text = s

End Sub
璉璉
2005-01-09 22:22:48 UTC
直接用 WebClient 即可,可參考下面位置:

http://tlcheng.no-ip.com/TLCheng/Net/NetList.aspx?Action=Function&Module=15&Function=89


此內容最初發佈在 Y! Answers 上,這是一個於 2021 年關閉的問答網站
Loading...