2015-11-08 63 views
-1

我想了解如何在VBA中使用getelements在HTML中處理單個td元素的概念,例如,如果我想解決103以下的最後一個td元素,我使用這個代碼和它的作品48,只是瞭解如何解決「td」元素

<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

這與[我想要獲取特定的HTML td標記]有何不同(http://stackoverflow.com/ques蒸發散/ 33586677 /我想做對獲得-A-特定HTML的TD-標籤)? – Jeeped

+0

Rocco,我們需要知道您是如何訪問該html代碼的,您是否有任何VBA代碼?你使用的是什麼庫/對象? (可能你會使用InternetExplorer對象或MSXML2庫...) –

+0

再看看@JasonK。 – Jeeped

回答

0

現在,經過「來自Prezzo迪chiusura?,我得到的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