我想了解如何在VBA中使用getelements在HTML中处理单个td元素的概念,例如,如果我想要解决下面的最后一个td元素,那里面有103,48和" Prezzo di chiusura?
<div class="instruments_company_summary">
<table class="table-noborders">
<tr>
<td class="table_label"> </td>
<td>
<div class="floatdx" style="padding-bottom:10px">
<div class="floatsx">
<div class="standard-button">
<a href="/it/strumenti/grafico/IT0004781073">Grafico</a> </div>
</div>
<div class="floatsx">
<div class="standard-button">
<a href="http://www.eurotlx.com/product-details/IT0004781073.pdf" target="_blank">Scheda</a> </div>
</div>
<div class="floatsx">
<div class="standard-button">
<a href="/it/strumenti/dettaglio/csv/IT0004781073">Scarica book</a> </div>
</div>
</div>
</td>
</tr>
<tr>
<td class="table_label">Isin</td>
<td>
<div class="floatsx" style="padding-top:4px;">IT0004781073</div>
</td>
</tr>
<tr>
<td class="table_label">Descrizione</td>
<td>Bpvi 8.5% Sink Sub 28dc18</td>
</tr>
<tr>
<td class="table_label">Prezzi aggiornati al</td>
<td>08-11-2015 13:51:45</td>
</tr>
</table>
<table>
<tr>
<th colspan="2">Book di negoziazione</th>
</tr>
<tr>
<td class="table_label">Var</td>
<td>0,10%</td>
</tr>
<tr>
<td class="table_label" style="border:0">Book a 5 livelli</td>
<td style="border:0; padding: 10px 0 5px">
<table>
<thead>
<tr>
<th>Q.tà Acquisto</th>
<th>Prezzo Acquisto</th>
<th>Prezzo Vendita</th>
<th>Q.tà Vendita</th>
</tr>
</thead>
<tbody>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
<table>
<tr>
<th colspan="2">Dati ultimo contratto</th>
</tr>
<tr>
<td class="table_label">Prezzo</td>
<td>103,6</td>
</tr>
<tr>
<td class="table_label">Quantità</td>
<td>24.000</td>
</tr>
<tr>
<td class="table_label">Data e ora</td>
<td>06-11-2015 17:29:41</td>
</tr>
</table>
<table>
<tr>
<th colspan="2">Dati giornalieri</th>
</tr>
<tr>
<td class="table_label">Prezzo di chiusura</td>
<td>103,48</td>
</tr>
答案 0 :(得分:0)
现在我正在使用这段代码并且它有效,我在网页中得到了我想要的td元素作为td编号,但我认为可以有更好的方法来识别td单元格。
Dim W As Worksheet: Set W = ActiveSheet
Dim Objie As Object
Dim xObj
Debug.Print URL
Set Objie = CreateObject("InternetExplorer.Application")
Objie.Visible = False
Objie.Navigate URL
While (Objie.Busy Or Objie.ReadyState <> 4)
DoEvents
Wend
Set xObj = Objie.Document.getElementsByTagName("td")(39)
W.Range("E" & Index + 1) = xObj.innerText
Set xObj = Nothing
Objie.Quit
Set Objie = Nothing