Обязательные ссылки через инструменты> ссылки
- Библиотека объектов HTML
- MS Internet Controls.
Примечание:
Другой вывод, который теперь выполняется в другой день для веб-сайта.
① Вот версия, которая анализирует только эти элементы:
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+~)+"