我想從網頁中使用vba將一些數據取消到Excel中。使用vba從跨度中提取內部文本
的HTML代碼是
<span id="lastPrice">300.21</span>
我想數300.21
我試過,但沒有工作(在ST返回任何內容)
Dim st As String
st = htmldoc.getElementById("lastPrice").getElementsByTagName("span")(5).innerText
我如何獲得期望的輸出?
我想從網頁中使用vba將一些數據取消到Excel中。使用vba從跨度中提取內部文本
的HTML代碼是
<span id="lastPrice">300.21</span>
我想數300.21
我試過,但沒有工作(在ST返回任何內容)
Dim st As String
st = htmldoc.getElementById("lastPrice").getElementsByTagName("span")(5).innerText
我如何獲得期望的輸出?
試試這個:
Dim element as Object
Set element = htmldoc.getElementById("lastPrice")
Dim price as String
If Not element Is Nothing Then price = element.innerText
它顯示了一個荒唐的輸出2200.00% – user3126632
這是從哪裏來的?網頁上的任何位置是否有顯示2200.00%的元素? –
不,我沒有在頁面上發現任何東西 – user3126632
你有使用多個元素' 「lastPrice」'作爲自己'ID'? – 2017-07-06 18:17:55
不,我沒有。這裏的鏈接https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=SBIN&illiquid=0&smeFlag=0&itpFlag=0 – user3126632
'document.getElementById(「lastPrice 「).innerText'使用Chrome控制檯返回正確的號碼。你能發佈更多的代碼或下載鏈接嗎? – 2017-07-06 18:49:35