Html VBA在form post div中刮取web表

Html VBA在form post div中刮取web表,html,vba,web-scraping,scrape,getelementsbytagname,Html,Vba,Web Scraping,Scrape,Getelementsbytagname,我正试图从以下网站获取web表数据,并提取掉期利率 让我们使用下面的代码,看看它是否抛出了所需的数据,但仍然得到错误91。我在获取元素规范中遗漏了什么?下面是我的代码 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://seb

我正试图从以下网站获取web表数据,并提取掉期利率

让我们使用下面的代码,看看它是否抛出了所需的数据,但仍然得到错误91。我在获取元素规范中遗漏了什么?下面是我的代码

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://sebgroup.com/large-corporates-and-institutions/prospectuses-and-downloads/rates/swap-rates"

' 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 from the specified element on the page.

price = html.getElementsByTagName("table")(0).innerText
' Output the price into a message box.
MsgBox price

数据在iframe中。向的iframe src提出请求

https://seb.se/pow/apps/swaprates/default.aspx
假设允许刮削

然后有10个表作为css选择器出现:#doc table

这意味着您可以使用
html.getElementById(“doc”).getElementsByTagName(“table”)
对于检索到的表,使用
html.queryselectoral(“doc table”)
并从
For i=0循环到html.queryselectoral(“doc table”).Length-1
并使用
html.queryselectoral(“doc table”)项(i)访问循环中的每个表。
把他们都弄到手。其中
i的长度为
。最好将结果放入变量并在循环中引用它


您可能只需将xhr请求的
.innerText
响应分配给
html.body.innerHTML
,而不使用
StrConv
,数据位于iframe内。向的iframe src提出请求

https://seb.se/pow/apps/swaprates/default.aspx
假设允许刮削

然后有10个表作为css选择器出现:#doc table

这意味着您可以使用
html.getElementById(“doc”).getElementsByTagName(“table”)
对于检索到的表,使用
html.queryselectoral(“doc table”)
并从
For i=0循环到html.queryselectoral(“doc table”).Length-1
并使用
html.queryselectoral(“doc table”)项(i)访问循环中的每个表。
把他们都弄到手。其中
i的长度为
。最好将结果放入变量并在循环中引用它


您可能只需将xhr请求的
.innerText
响应分配给
html.body.innerHTML
,而不使用
StrConv

这正是我想要的答案,iframe规范未被捕获。一周来,我们一直在努力找出导致此错误的原因,非常感谢您的快速输入!事实上,如果我可以再问一个问题的话。如何获取网页表格中的“保单费率”?看起来这里没有iframe问题,仍然会再次出现相同的错误。提前感谢你需要问一个新问题,分享你的代码,并解释什么不起作用。好的,谢谢,将以新问题的形式发布在新的线程中。这正是我想要的答案,iframe规范未被接受。一周来,我们一直在努力找出导致此错误的原因,非常感谢您的快速输入!事实上,如果我可以再问一个问题的话。如何获取网页表格中的“保单费率”?看起来这里没有iframe问题,仍然会再次出现相同的错误。提前感谢您需要提出一个新问题,分享您的代码,并解释什么不起作用。好的,谢谢,将以新问题的形式在新帖子中发布。