我想使用excel從網站中取消一些信息。從網站中提取數據作爲單獨的字段
這是顯示了源:
<tr class="even">
<td align="right">1</td>
<td><a href="/kld/en/1.html">Acrobatic Maneuver</a></td>
<td>Instant</td>
<td>2W</td>
<td>Common</td>
<td>Winona Nelson</td>
<td><img src="http://magiccards.info/images/en.gif" alt="English" width="16" height="11" class="flag2"> Kaladesh</td>
</tr>
所以我想擁有的一切,甚至,和<td></td>
然而之間提取數據,所有我發現到現在爲止是這樣的代碼
Sub getcards()
Dim IE As Object
Dim i As Long
Dim objCollection As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = False
' URL to get data from
IE.Navigate "http://magiccards.info/query?q=%2B%2Be%3Akld/en&v=list&s=issue"
' Statusbar
Application.StatusBar = "Loading, Please wait..."
' Wait while IE loading...
Do While IE.Busy
DoEvents
Application.Wait DateAdd("s", 1, Now)
Loop
On Error GoTo abort
Application.StatusBar = "Searching for value. Please wait..."
Dim dd As String
Set objCollection = IE.document.getElementsByClassName("even")
For i = 0 To objCollection.Length
dd = IE.document.getElementsByClassName("even")(i).innerText
MsgBox dd
Next i
abort:
' Show IE
IE.Visible = True
IE.Quit
' Clean up
Set IE = Nothing
Application.StatusBar = ""
End Sub
它的工作原理,它提取數據的方式,但輸出1Acrobatic ManeuverInstant2WCommonWinona Nelson Kaladesh
一起。
我該怎麼做才能理解每個<td>
作爲一個單獨的字段,所以我可以輕鬆提取它?
'IE.document.getElementsByClassName( 「甚至」)(一).getElementsByTagName( 「TD」)(X)'你需要一個遍歷集合,其中x是該項目。 –
嘗試使用'IE.document.getElementsByClassName(「even」)(i).getElementsByTagName(「td」)(1)'但它返回的是[object HTMLTableDataCellElement]' – Moacir
所以添加.innerText然後:) –