【发布时间】:2021-02-25 22:53:22
【问题描述】:
我正在尝试使用 MSXML2.XMLHTTP 获取数据 但它没有工作
有什么想法吗?
Sub getdata
Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim price As String
Dim sht As Worksheet
Application.DisplayAlerts = False
Set sht = ActiveSheet
On Error Resume Next
website = "https://shopee.co.id/AFI-EC-Tshirt-Yumia-(LD-90-P-57)-i.10221730.5568491283"
Set request = CreateObject("MSXML2.XMLHTTP")
request.Open "GET", website, False
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
request.send
response = StrConv(request.responseBody, vbUnicode)
html.DocumentElement.innerHTML = response
price = html.querySelector("div.AJyN7v")(0).innerText
Debug.Print price
Application.StatusBar = ""
On Error GoTo 0
Application.DisplayAlerts = True``
End Sub
我做了很多方法,但仍然没有工作, 希望有人可以帮助我
【问题讨论】:
-
“没有工作”不是对运行代码时发生的情况的有用描述。你有错误吗?如果是什么错误和哪一行。请查看How to Ask 并考虑通过一些额外的细节改进您的帖子。
-
没有错误信息
-
您可以尝试运行我的代码吗?我想得到价格
-
尝试不使用
On Error Resume Next -
有错误信息 Object variable or With block variable not set
标签: vba web-scraping