我正在尝试获取标签的内部文本,但出现错误。通过控制台,我成功地使用此脚本获取了内部文本:
document.getElementsByClassName("item alt")[0].childNodes[2].childNodes[0].innerText
我想要得到的元素:
<tr class="item alt" data-id="1376936"><td class="toolbar left"><a href="#" class="show-incidents button-small ui-state-transparent-default rc" title="Details"><span class="ui-icon ui-icon-triangle-1-e"></span></a></td><td class="time">14:00</td><td class="status"><span class="status-1 rc">FT</span>
我的 VBA 脚本:
Sub WebScraping()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://www.whoscored.com/Regions/74/Tournaments/22/Seasons/7814/Stages/17593/Fixtures/France-Ligue-1-2019-2020"
Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to Whoscored ..."
DoEvents
Loop
Set doc = ie.document
Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to Whoscored ..."
DoEvents
Loop
Set a = doc.getElementsByClassName("item alt")(0).ChildNodes(2).ChildNodes(0).innerText
MsgBox (a)
End Sub