2014-02-20 49 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