通过工具所需的参考资料>参考文献
-
HTML对象库
-
MS Internet控件。
注:
不同的输出,现在运行在不同的一天对网站。
以下是一个仅解析这些项目的版本:
Option Explicit
Public Sub PrintMatchInfo()
Application.ScreenUpdating = False
Dim IE As InternetExplorer, doc As HTMLDocument
Set IE = New InternetExplorer
With IE
.Visible = True
.Navigate2 "https://azscore.com/en/yesterday"
While .Busy Or .readyState < 4: DoEvents: Wend
Set doc = .document
End With
Dim games As Object, i As Long, j As Long, counter As Long
counter = 1
Set games = doc.getElementsByClassName("game_table")
For i = 0 To games.Length - 1
For j = 0 To games(i).getElementsByClassName("game_detailsCol").Length - 1
With ThisWorkbook.Worksheets("Sheet2")
.Cells(counter, 1) = Split(games(i).innerText, Chr$(10))(3)
Dim tempArr() As String
tempArr() = Split(GetKeyDetails(ReplacedString(games(i).getElementsByClassName("game_detailsCol")(j).innerText)), Chr$(126))
.Cells(counter, 2).Resize(1, UBound(tempArr) + 1) = tempArr
counter = counter + 1
End With
Next j
Next i
Application.ScreenUpdating = True
End Sub
Public Function ReplacedString(ByVal str As String) As String
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "\s{2,}"
End With
ReplacedString = regex.Replace(str, Chr$(126)) '<== or other unexpected character
End Function
Public Function GetKeyDetails(ByVal inputString As String) As String
Dim regex As Object, tempString As String
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "(^[A-Z](?:\d|[01]\d|2[0-3]):[0-5]\d~)(\d?~?)+" '"^[A-Z](?:\d|[01]\d|2[0-3]):[0-5]\d~(\d~)?(\d~)?|x\~Head To Head"
End With
tempString = regex.Replace(inputString, vbNullString)
Dim tempArr() As String
tempArr = Split(tempString, Chr$(126))
Dim keyDetails(), outputString As String, detail As Long
keyDetails = Array(0, 1, 2, 3)
For detail = LBound(keyDetails) To UBound(keyDetails)
outputString = outputString & Chr$(126) & tempArr(keyDetails(detail))
Next detail
GetKeyDetails = Trim$(outputString)
End Function
输出:
–包含所有信息的版本:
代码:
Option Explicit
Public Sub PrintAllMatchInfo()
Application.ScreenUpdating = False
Dim IE As InternetExplorer, doc As HTMLDocument
Set IE = New InternetExplorer
With IE
.Visible = True
.Navigate2 "https://azscore.com/en/yesterday"
While .Busy Or .readyState < 4: DoEvents: Wend
Set doc = .document
End With
Dim games As Object, i As Long, j As Long, counter As Long
counter = 1
Set games = doc.getElementsByClassName("game_table")
For i = 0 To games.Length - 1
For j = 0 To games(i).getElementsByClassName("game_detailsCol").Length - 1
With ThisWorkbook.Worksheets("Sheet1")
.Cells(counter, 1) = Split(games(i).innerText, Chr$(10))(3)
.Cells(counter, 2) = ReplacedString(games(i).getElementsByClassName("game_detailsCol")(j).innerText)
counter = counter + 1
End With
Next j
Next i
Application.ScreenUpdating = True
End Sub
Public Function ReplacedString(ByVal str As String) As String
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "\s{2,}"
End With
ReplacedString = regex.Replace(str, " ") '<== or other unexpected character
End Function
输出:
后续问题的模式:
"^\w+\/(\d+~)+"