在 table 中抓取特定数据
Scraping specific data inside a table
这可能是一个非常简单的解决方案,但即使我感觉很接近,我也不知所措。
我正在尝试从 TMX 网站上抓取市场数据,特别是我希望将股息金额放入我的 excel 工作簿中。
这是 "inspect" 部分的以下几行代码。
<table class="table">
<tbody>
<tr>
<td>
<strong>Amount:</strong>
[=11=].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:" 并将其放入单元格中,而不是我需要的值,位于下一行。
Dim v
For Each htmlELE In ieObj.document.getElementsByClassName("table")(0). _
.getElementsByTagName("tr")(0).getElementsByTagName("td")
v = htmlELE.innerText
' is CHR(160)
ActiveSheet.Range("L10").Value = trim(Replace(v, "Amount:" & chr(160),""))
'or lookfor the $ and take the rest
p = Instr(v, "$")
If p > 0 Then ActiveSheet.Range("L10").Value= Mid(v, p)
这可能是一个非常简单的解决方案,但即使我感觉很接近,我也不知所措。
我正在尝试从 TMX 网站上抓取市场数据,特别是我希望将股息金额放入我的 excel 工作簿中。
这是 "inspect" 部分的以下几行代码。
<table class="table">
<tbody>
<tr>
<td>
<strong>Amount:</strong>
[=11=].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:" 并将其放入单元格中,而不是我需要的值,位于下一行。
Dim v
For Each htmlELE In ieObj.document.getElementsByClassName("table")(0). _
.getElementsByTagName("tr")(0).getElementsByTagName("td")
v = htmlELE.innerText
' is CHR(160)
ActiveSheet.Range("L10").Value = trim(Replace(v, "Amount:" & chr(160),""))
'or lookfor the $ and take the rest
p = Instr(v, "$")
If p > 0 Then ActiveSheet.Range("L10").Value= Mid(v, p)