【发布时间】:2020-08-15 22:30:02
【问题描述】:
我是网络抓取和 VBA 的新手,但我渴望进一步学习。 我有一个小项目,正在一步一步地慢慢完成。 我在一个几乎可以工作的 Excel 模块中有一小段代码。我只是无法让它提交我的搜索框文本。 我的 Excel 工作表中的单元格 A2 中基本上有示例马名。该代码会打开网站并将文本输入到搜索框中。 我只是无法让它单击“开始”按钮。 我将不胜感激任何帮助和解释我做错了什么,以便我可以再次避免它!
当检查网站上的 Go 按钮时,HTML 如下:
我的代码:
Sub HorseSearch()
'define objIE
Dim objIE As InternetExplorer
'create an instance objIE
Set objIE = New InternetExplorer
'make web page visible
objIE.Visible = True
'navigate objIE to this web page
objIE.navigate "https://www.britishhorseracing.com/racing/horses/racehorse-search-results/"
'wait here a few seconds while the browser is busy
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
'in the search box put cell "A2" value which holds a horse name Tiger Roll
objIE.document.getElementById("text-search").Value = Sheets("Sheet1").Range("A2").Value
'place focus on the Go button
objIE.document.getElementById("Submit").Focus
'click the 'go' button
objIE.document.getElementById("Submit").Click
End Sub
【问题讨论】:
标签: excel vba search click box