在表内抓取特定数据

问题描述 投票:1回答:1

这可能是一个非常简单的解决方案,但是即使我感到很亲近,我还是很茫然。

我正在尝试从TMX网站上抓取市场数据,特别是我希望股息金额落入我的excel工作簿中。

这是“检查”部分中的以下几行代码。

<table class="table">
  <tbody>
    <tr>
      <td>
        <strong>Amount:</strong>&nbsp;
        $0.0495
      </td>

我需要在工作簿中获取$ 0.0495,而我的vba代码如下:

For Each htmlELE In ieObj.document.getElementsByClassName("table")(0).getElementsByTagName("tr")(0).getElementsByTagName("td")
    With ActiveSheet
        .Range("L10").Value = htmlELE.Children(0).innerText
    End With

所以,我在遍历代码,但最后一直选择“ Amount:”并将其放在单元格中,而不是我需要的值放在下一行。

html excel vba web-scraping getelementsbytagname
1个回答
0
投票
Dim v
For Each htmlELE In ieObj.document.getElementsByClassName("table")(0). _
               .getElementsByTagName("tr")(0).getElementsByTagName("td")

    v = htmlELE.innerText
    '&nbsp; is CHR(160)
    ActiveSheet.Range("L10").Value = trim(Replace(v, "Amount:" & chr(160),""))
© www.soinside.com 2019 - 2024. All rights reserved.