我想将在 html 表中找到的所有项目存储在字典中。
当我有重复项时我会遇到问题,因为我下面的代码不会再次存储该项目,并且我需要此表中的所有项目,即使有任何重复项。
如果我有像Round 38这样的重复值,其中另一个Match3具有相同的轮数,我想再次列出这些重复值。
结果应如下所示:
第38轮
比赛1
比赛2
第37轮
比赛1
比赛2
第38轮
比赛3
比赛4
.....................
Sub Get_URL_Addresses_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.ro/fotbal/anglia/premier-league-2015-2016/rezultate/"
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
objLink.Click
Application.Wait (Now + TimeValue("0:00:01"))
objLink.Click
Application.Wait (Now + TimeValue("0:00:01"))
objLink.Click
Application.Wait (Now + TimeValue("0:00:01"))
'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
For Each tRow In tRows
If tRow.getAttribute("Class") = "event_round" Then
tRowClass = tRow.innerText
'MsgBox tRowClass
If Not .Exists(tRowClass) Then
.add tRowClass, Empty
End If
End If
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
If Left(Key, 5) = "Runda" Or Left(Key, 5) = "Round" Then
ActiveSheet.Cells(i, 2) = Key
Else
ActiveSheet.Cells(i, 2) = "http://www.flashscore.ro/meci/" & Key & "/#sumar-meci"
End If
i = i + 1
'MsgBox Key
'Debug.Print Key
Next Key
Set ie = Nothing
MsgBox "Process Completed"
End Sub