當前位置:編程學習大全網 - 源碼下載 - vb6用xmlhttp的方法獲取網站源代碼 -2147024891(80070005)錯誤

vb6用xmlhttp的方法獲取網站源代碼 -2147024891(80070005)錯誤

這個不完美,我來補個完美的,並有超時設定,這樣抓數據就灰常的可以等待,沒有太快的超時了.

Public Function getHtmlStr(strURL)

On Error GoTo ErrorHandler

Dim XmlHttp As Object

Set XmlHttp = Nothing

Set XmlHttp = CreateObject("msxml2.serverxmlhttp")

XmlHttp.Open "GET", strURL, True ' false同步,true異步

XmlHttp.SetTimeouts 10000, 10000, 10000, 30000

XmlHttp.send

Dim waitTimeOut, secondNumber

waitTimeOut = 0

secondNumber = 30 '超時多少秒

Do

DoEvents

wait 10

waitTimeOut = waitTimeOut + 1

Loop Until (XmlHttp.ReadyState = 4 Or waitTimeOut >= 100 * secondNumber)

If XmlHttp.ReadyState = 4 Then

getHtmlStr = XmlHttp.Responsebody

lianjie = True

Set XmlHttp = Nothing

Exit Function

End If

ErrorHandler:

lianjie = False

Set XmlHttp = Nothing

End Function

上面是函數.下面是調用示例:

Dim ss As String

ss = BytesToBstr(getHtmlStr(Text1.Text), "utf-8") & vbCrLf

If lianjie = True Then

PASSRichTextBox3.Text = "采集成功"

Else

PASSRichTextBox3.Text = "采集失敗"

End If

'Public Function BytesToBstr(strBody, CodeBase)

' On Error Resume Next

' Dim ObjStream

' Set ObjStream = CreateObject("Adodb.Stream")

' With ObjStream

' .Type = 1

' .Mode = 3

' .open

' .Write strBody

' .Position = 0

' .Type = 2

' .charset = CodeBase

' BytesToBstr = .ReadText

' .Close

' End With

' Set ObjStream = Nothing

'End Function

  • 上一篇:通達信軟件應用黃金分割在哪裏找?
  • 下一篇:java,Swing,JTable,如何實現帶豎標題的表格
  • copyright 2024編程學習大全網