當前位置:編程學習大全網 - 源碼下載 - vb如何讀取網頁源碼制定位置內容

vb如何讀取網頁源碼制定位置內容

'我用的當前頁搜索的,註意網頁的編碼!

Private Sub Form_Load()

URL1 = "/question/151539391.html?push=category"

wstr1 = getHTTPPage(URL1, "GB2312") 'UTF-8 註意網頁的編碼

a = InStr(1, wstr1, "您的消費金額是:")

b = InStr(a + 8, wstr1, "元")

Text1.Text = Trim(Mid(wstr1, a + 8, b - a - 7))

End Sub

Function getHTTPPage(URL, Cset) '從網絡讀取文件

Dim http

On Error Resume Next

Set http = CreateObject("MSXML2.XMLHTTP")

http.open "GET ", URL, False

http.send

If Err.Number = -2146697211 Then

If zidong = 1 Or zidong = 2 Or zidong = 3 Then

Else

MsgBox "網絡不通,連通後再試壹試!!"

End If

Exit Function

End If

If http.readyState <> 4 Then

Exit Function

End If

getHTTPPage = BytesToBstr(http.responseBody, Cset)

Set http = Nothing

If Err.Number <> 0 Then Err.Clear

End Function

Function BytesToBstr(body, Cset) '從網絡讀取文件

Dim objstream

Set objstream = CreateObject("adodb.stream")

objstream.Type = 1

objstream.Mode = 3

objstream.open

objstream.Write body

objstream.Position = 0

objstream.Type = 2

objstream.Charset = Cset

BytesToBstr = objstream.ReadText

objstream.Close

Set objstream = Nothing

End Function

  • 上一篇:描述是什麽意思?如何解決這個問題?
  • 下一篇:linux工程師證書Linux認證工程師
  • copyright 2024編程學習大全網