2017-04-21 33 views
0

我嘗試從https://www.top40.nl/top40/2017/week-14下載前40位,但我沒有得到比記錄中所有前40位記錄中的1大數據組更多的數據。任何人都可以幫我用正確的代碼來獲取這些數據嗎?我只是需要一個位置,藝術家和歌詞。在MS Access表格中導入來自互聯網的前40位數據

這是我到目前爲止。

Dim IE As Object 
Dim dd As Variant 


Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = False 
IE.navigate "https://www.top40.nl/top40/2017/week-14" 

Do While IE.Busy 
    DoEvents 
Loop 

dd = IE.Document.getElementsByClassName("top40")(0).InnerText 

Set IE = Nothing 
Set objElement = Nothing 
Set objCollection = Nothing 

image HTML code

+0

你可以顯示的HTML而不是鏈接請你。 –

+0

我添加了部分代碼的圖像 –

回答

1

試試這個:

Dim Element As IHTMLElement 
Dim i As integer 
Dim artist as String 
Dim position As Integer 
For i=0 To IE.Document.getElementsByClassName("top40")(3).Children.Length 
     position = IE.Document.getElementsByClassName("top40")(0).Children(i).Children(0).innertext 
     artist = IE.Document.getElementsByClassName("top40")(3).Children(i).Children(2).Children(3).Children(1).Children(1).innertext 
Next i 

而對於這張專輯的名字,我讓你扣同樣的方式:)

說明:

1)爲什麼(「top40」)(3) - >MsgBox IE.Document.getElementsByClassName("top40").length返回4,這意味着沒有一個與類名獨特的元素,所以要選擇正確的,你可以舉例來說做到這一點:

For i = 0 to IE.Document.getElementsByClassName("top40").length 
MsgBox IE.Document.getElementsByClassName("top40")(i).tagname 'you'll only get one with the OL tagname which is the last one (4th element but index 3) 
Next i 

2)然後要經過的元素進行如下所示(這是一個出路的多種方式來做到這一點我並不是說這是最好的一個):

  • 在檢查中,點擊小箭頭,它允許您選擇頁面上的任何元素 - >您選擇。例如藝術家的名字第一個位置 - >這會告訴你它的一小段HTML代碼。
  • 從窗體「top40」到這個特定的元素,您可以通過子節點或子節點進行導航。學習如何使用Watch窗口來瀏覽不同的元素。兒童(3)例如是指第四名兒童。

讓我知道你是否需要更多細節。

+0

您是否能夠使其工作?我在'position ='和'artist ='上遇到了一個類型不匹配的問題......我正準備寫自己的解決方案(但你的看起來好多了) - 也許我錯過了一個引用或其他東西? –

+0

還沒有。但我得到了一些信息。您必須參考Microsoft HTML對象庫和Microsoft Internet控件。讓我知道,如果你得到它的工作和出錯的地方?我會繼續嘗試:-) –

+0

是的,這些參考是必需的。告訴我是否出現問題(線路消息)。我寫它沒有嘗試它,但它應該工作。 – Seb