在VBA中使用XMLHTTP从多个页面解析/清除

时间:2015-07-16 22:40:47

标签: excel vba excel-vba web-scraping xmlhttprequest

下面的代码只会将一页数据(50个结果)擦除/解析为excel但是,我希望它能刮掉多个页面(500个结果) - 请帮忙。 (Base64Encode来自不同的来源 - 我不赞成它)

`Function GetData() As Boolean
 Application.ScreenUpdating = False


 Dim objHTTP As New MSXML2.XMLHTTP

 Dim strURL As String
 Dim strUserName As String
 Dim strPassword As String


 Sheet1.Range("A2:R2000") = ""

 Sheet1.Activate

 strUserName = "User"
 strPassword = "Password"

 For i = 1 To UBound(MyArray)

 strURL = "https://.ngx.com/ngxcs/indexPrice.xml" 
 objHTTP.Open "GET", strURL, False
 objHTTP.setRequestHeader "Authorization", "Basic " & Base64Encode(strUserName & ":" & strPassword)
objHTTP.setRequestHeader "Host", "secure.example.com"
objHTTP.setRequestHeader "Content-Type", "text"

objHTTP.send "Nothing"

While objHTTP.readyState <> 4
   DoEvents
Wend

Dim strResponseReceived As String

strResponseReceived = objHTTP.responseText
Debug.Print objHTTP.responseText
MsgBox strResponseReceived


Dim xDoc As DOMDocument
Set xDoc = New DOMDocument

xDoc.LoadXML objHTTP.responseText`

'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 将其输出到excel的其余代码

感谢您的帮助!

0 个答案:

没有答案