【发布时间】:2021-01-01 00:34:42
【问题描述】:
我正在尝试从以下网站获取网络表格数据,并在右侧提取有关保单费率的第一个表格。
https://www.researchonline.se/macro/our_forecasts
使用以下代码只是为了查看它是否吐出所需的数据,但不断收到错误 91。怀疑我需要在我的代码中考虑的关于 Javascript 的某些内容?下面是我的代码。
Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim price As Variant
' Website to go to.
website = "https://www.researchonline.se/macro/our_forecasts"
' Create the object that will make the webpage request.
Set request = CreateObject("MSXML2.XMLHTTP")
' Where to go and how to go there - probably don't need to change this.
request.Open "GET", website, False
' Get fresh data.
request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
' Send the request for the webpage.
request.send
' Get the webpage response data into a variable.
response = StrConv(request.responseBody, vbUnicode)
' Put the webpage into an html object to make data references easier.
html.body.innerHTML = response
' Get the price variable from the specified element on the page and just check in a message box if that is the correct data.
price = html.getElementsByTagName("table")(0).innerText
' Output the price into a message box.
MsgBox price
【问题讨论】:
标签: javascript vba web-scraping