【发布时间】:2021-07-16 18:11:58
【问题描述】:
我正在尝试使用 Excel VBA macros 抓取网站。但是,我无法使用以下代码选择drop down 列表:
Public Sub Public_Data_pulled()
Application.Calculation = xlCalculationAutomatic
Dim html As HTMLDocument, hTable As HTMLTable
Set html = New HTMLDocument
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://www.seleniumeasy.com/test/basic-select-dropdown-demo.html", False
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send
html.body.innerHTML = .responseText
End With
Application.ScreenUpdating = False
Set hTable = html.getElementById("select-demo")
Title.selectedIndex = 5
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
通过id获取元素后
hTable的值是多少? -
Title在表达式Title.selectedIndex = 5中来自哪里? -
我不确定你想通过使用 xmlhttp 执行
select之类的交互来完成什么。
标签: excel vba web-scraping