我在 Excel VBA 中使用 Selenium 來抓取一些網站。我希望在網頁上找到類似于以下代碼段的所有元素:
<div data-automation-id="racecard-outcome-name"><span >1. The Running Man</span><span > (5)</span></div>
特別是,我希望找到包含該屬性的所有元素,data-automation-id然后按具有racecard-outcome-name該屬性的元素進行過濾,但是一旦我可以回傳具有該屬性的所有元素,這應該很容易。
目前我正在使用類似于
table = bot.FindElementsBy.Attribute("data-automation-id")
但我知道這是對這個運算子的錯誤使用。如果你能指出我正確的方向,請告訴我。
uj5u.com熱心網友回復:
感謝 QHarr 提供有用的評論。我最終實施了以下解決方案來查找data-automation-id已標記的元素racecard-outcome-name:
Set table = bot.FindElementsByCss("[data-automation-id]")
Dim i As Integer, tableCount As Integer
tableCount = table.count
For i = 1 To table.count
If table(i).Attribute("data-automation-id") = "racecard-outcome-name" Then
MsgBox table(i).Text
End If
Next i
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/433138.html
