如何在 VBScript 中使用 HTML 标记解析网页
How do I parse a WebPage using HTML tags in VBScript
我尝试使用 VBScript 从 https://coinmarketcap.com/ 中提取比特币的价格。
我有以下 HTML 代码:
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">,329.61</a>
</td>
所以我为 vbs 文件编写了这个脚本:
set objIE =nothing
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = false
objIE.Navigate "https://coinmarketcap.com/"
Do
WScript.Sleep 100
Loop Until objIE.ReadyState = 4
msgbox objIE.document.getElementsByTagName("/currencies/bitcoin/#markets")
objIE.Quit()
我的预期结果是“4329.6071152”,但实际结果是:
您将通过查询获得 HTML 个节点的集合。您应该尝试更具体的一个并获取其属性:
MsgBox objIE.document.QuerySelectorAll("a[href='/currencies/bitcoin/#markets']").Item(0).getAttribute("data-usd")
因为 table 的行设置了 id 属性。您可以通过这种方式获取单元格的文本内容:
objIE.document.GetElementById("id-bitcoin").Cells(3).InnerText
我尝试使用 VBScript 从 https://coinmarketcap.com/ 中提取比特币的价格。 我有以下 HTML 代码:
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">,329.61</a>
</td>
所以我为 vbs 文件编写了这个脚本:
set objIE =nothing
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = false
objIE.Navigate "https://coinmarketcap.com/"
Do
WScript.Sleep 100
Loop Until objIE.ReadyState = 4
msgbox objIE.document.getElementsByTagName("/currencies/bitcoin/#markets")
objIE.Quit()
我的预期结果是“4329.6071152”,但实际结果是:
您将通过查询获得 HTML 个节点的集合。您应该尝试更具体的一个并获取其属性:
MsgBox objIE.document.QuerySelectorAll("a[href='/currencies/bitcoin/#markets']").Item(0).getAttribute("data-usd")
因为 table 的行设置了 id 属性。您可以通过这种方式获取单元格的文本内容:
objIE.document.GetElementById("id-bitcoin").Cells(3).InnerText