2017-01-09 19 views
1

我使用下面的代码来加载网站http://www.flashscore.com/soccer/england/premier-league/results/使用VBA列出网页的所有URL地址

当我找到并点击“显示更多匹配”链接后,所有的足球比赛都加载到浏览器中。

下面的代码将会给作为结果只有比赛的前半部分,该事件按“显示更多的匹配”链接之前显示。

我的问题是如何列出所有事件URL地址?

Sub Test_Flashscore() 

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/results/" 

With ie 
    .navigate URL 
    .Visible = True 
    Do Until .readyState = READYSTATE_COMPLETE: DoEvents: Loop 
    Set HTMLdoc = .document 
End With 


For Each objLink In ie.document.getElementsByTagName("a") 

    If Left(objLink.innerText, 4) = "Show" Or Left(objLink.innerText, 4) = "Arat" Then 

     MsgBox "The link was founded!" 
     objLink.Click 

     Exit For 

    End If 

Next objLink 


With HTMLdoc 

    Set tblSet = .getElementById("fs-results") 
    Set mTbl = tblSet.getElementsByTagName("tbody")(0) 
    Set tRows = mTbl.getElementsByTagName("tr") 
    With dictObj 
     'If if value is not yet in dictionary, store it. 
     For Each tRow In tRows 
      'Remove the first four (4) characters. 
      tRowID = Mid(tRow.ID, 5) 
      If Not .Exists(tRowID) Then 
       .add tRowID, Empty 
      End If 
     Next tRow 
    End With 
End With 

i = 14 
For Each Key In dictObj 

    ActiveSheet.Cells(i, 2) = "http://www.flashscore.com/" & Key & "/#match-summary" 
    i = i + 1 

Next Key 

Set ie = Nothing 
MsgBox "Process Completed" 

End Sub 

回答

0

你需要等待一小会儿的内容加载的其余部分 - 点击链接打完一个GET请求到服务器,这样就需要返回内容和内容需要对要呈现然后才能抓住它。

相关问题