如何从HTML代码中获取“tr id”?

时间:2017-01-09 14:14:13

标签: html excel vba

我想使用VBA从网页上获取不同链接的URL地址,但没有成功。有谁知道为什么我的代码不起作用?

我的代码如下:

Sub Test() 
Dim URL As String 
Dim IE As New InternetExplorer 
Dim HTMLdoc As HTMLDocument 
Dim dictObj As Object: Set dictObj = CreateObject("Scripting.Dictionary") 
Dim tRowID As String 

URL = "http://www.flashscore.com/soccer/england/premier-league/"; 
With IE 
    .Navigate URL 
    .Visible = True Do Until 
    .ReadyState = READYSTATE_COMPLETE: DoEvents: Loop Set HTMLdoc = .Document 
End With 
With HTMLdoc 
    Set tblSet = .getElementById("fs-results") 
    Set mTbl = tblSet.getElementsByTagName("tbody")(1) 
    Set tRows = mTbl.getElementsByTagName("tr")
    With dictObj 
        For Each tRow In tRows 
            tRowID = Mid(tRow.getAttribute("id"), 5) 
            If Not .Exists(tRowID) Then .Add tRowID, Empty 
            End If 
        Next tRow 
    End With 
End With 
For Each Key In dictObj 
    Debug.Print Key 
Next Key 
Set IE = Nothing 
End Sub

0 个答案:

没有答案