2014-02-20 92 views
0

顯示我必須從http://www.idealo.de/preisvergleich/OffersOfProduct/143513.html最後一列不從表

得出價格表到目前爲止,我已經做到了這一點代碼

Sub test()  

    Set sht = Sheets("Tabelle4") 
    rCount = 1 

    Dim objIE As Object, objTbl As Object, objTR As Object 
    Set objIE = CreateObject("InternetExplorer.application") 

    With objIE 
     .Visible = True 
     .Navigate "http://www.idealo.de/preisvergleich/OffersOfProduct/143513.html" 

     Do While .Busy Or .ReadyState <> 4 
      DoEvents 
     Loop 

     Set objTbl = objIE.Document.getElementById("offers-list") 
     Set objTR = objTbl.getElementsByTagName("tr") 


     rCount = 1 
     On Error Resume Next 
     For Each td In objTR 
      Cells(rCount, 1) = td.all(0).outerText 
      Cells(rCount, 2) = td.all(4).innerText 

      'Cells(rCount, 3) = td.all(2).outerText 
      'Cells(rCount, 4) = td.all(3).outerText 

      'Cells(rCount, 6) = td.all(5).innerText 
      'Cells(rCount, 7) = td.all(6).innerText 
      rCount = rCount + 1 
     Next 
     On Error GoTo 0 

    End With 

    objIE.Quit 
    Set objIE = Nothing 

End Sub 

它給了我前兩列,但包含的最後一列店名不顯示。任何人都可以幫助哪一個是最後一列的td()

+0

你爲什麼要使用VBA這種情況的TD對象?一個簡單的Data | From Web可以爲你提供你想要的一切嗎?你可能想看看[2]使用Excel的內置設施從網絡獲取數據](http://stackoverflow.com/questions/8798260/html-parsing-of-cricinfo-scorecards/8846791#8846791)我剛試過它的工作原理。 –

+0

@SiddharthRout我需要開發一個價格比較工具,這就是爲什麼在上面的鏈接中使用vba – user3305327

+0

的情況,還有vba代碼。 –

回答

0

爲了確定每個td對象有哪些類型的數據,您必須將它們添加到手錶中。例如:

enter image description here

enter image description here

enter image description here

正如你所看到的,在TD對象,我看我可以告訴的

td.all.item(0).innertext 

值是: 佳能Nahlinse 500D 72毫米

現在,你應該通過在監視窗口中的其他值,直到你可以找到店鋪的指數

+1

這是代碼基於相同的代碼,我在下面的鏈接提到的問題;) –

+0

確實:) ...... – Pedrumj

+0

謝謝你的代碼,但如果我想只派生一個特定的表... 。我使用了.WebTables =「offers-list」,但它給了我錯誤 – user3305327