簡體   English   中英

獲取 HTML 元素的值

[英]Getting the value of an HTML Element

我這里有這段代碼,它應該在這個 Reddit 頁面上找到一個 HTML 元素,然后從中返回一個值,然后將其存儲在從零開始的一維數組中。 (我有一個名為 IE 的 Internet Explorer 實例)

Dim awardelements As Object
Dim awards As String

    awardelements = IE.document.querySelector("#siteTable > div")(0)
    awards = awardelements.getAttribute("data-gildings")
    results(i + 1, 14) = awards

所以我試圖獲得“data-gildings”的價值(帖子獲得的獎項數量),但我在awardelements = IE.document.querySelector("#siteTable > div")(0)上遇到自動化錯誤awardelements = IE.document.querySelector("#siteTable > div")(0)線。 我不確定我是否可以像 tbh 那樣使用 JS querySelector,所以這可能是問題所在。 如果有人能指出我正確的方向,我將不勝感激!

謝謝^^

querySelector返回單個節點,而不是您可以索引的集合。 並且您需要如上所述的 Set 關鍵字。

Dim awards As Object, awardCount As String

Set awards = ie.document.querySelector("#siteTable > div")
awardCount = awards.getAttribute("data-gildings")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM