2020年7月13日 星期一

vb.net 直接取得網頁源碼(非WebBrowser) [Get HTML Source (not WebBrowser)]


1
2
Imports System.Net
Imports System.IO





 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    Private Function getHTML(ByVal Address As String) As String
        Dim rt As String = ""
        Dim wRequest As WebRequest
        Dim wResponse As WebResponse

        Dim SR As StreamReader

        wRequest = WebRequest.Create(Address)
        wResponse = wRequest.GetResponse

        SR = New StreamReader(wResponse.GetResponseStream)
        'SR = New StreamReader(wResponse.GetResponseStream, System.Text.Encoding.GetEncoding(950)) '繁中
        'SR = New StreamReader(wResponse.GetResponseStream, System.Text.Encoding.GetEncoding(936)) '簡中

        rt = SR.ReadToEnd
        SR.Close()
        Return rt
    End Function

沒有留言:

張貼留言