Вам не нужен браузер. Вы можете использовать быстрее XHR. Возьмите таблицу и l oop строки, а затем столбцы, заполняющие массив заданного размера (обязательно удалите строки, в которых находятся заголовки. Их можно идентифицировать как имеющие [colspan='2']
в их первом td
). Затем перенесите массив и запишите на лист.
Option Explicit
Public Sub TransposeTable()
Dim xhr As MSXML2.XMLHTTP60, html As MSHTML.HTMLDocument, table As MSHTML.htmltable
'required VBE (Alt+F11) > Tools > References > Microsoft HTML Object Library ; Microsoft XML, v6 (your version may vary)
Set xhr = New MSXML2.XMLHTTP60
Set html = New MSHTML.HTMLDocument
' 7NXBG2 ; 8QT2E3
With xhr
.Open "GET", "https://www.chrono24.com/watch/8QT2E3", False
.send
html.body.innerHTML = .responseText
End With
Set table = html.querySelector(".specifications table")
Dim results(), rowCountToExclude As Long
rowCountToExclude = html.querySelectorAll(".specifications table [colspan='2']").Length
ReDim results(1 To table.rows.Length - rowCountToExclude, 1 To table.getElementsByTagName("tr")(0).Children(0).getAttribute("colspan"))
Dim r As Long, c As Long, outputRow As Long, outputColumn As Long, html2 As MSHTML.HTMLDocument
Set html2 = New MSHTML.HTMLDocument
For r = 0 To table.getElementsByTagName("tr").Length - 1
Dim row As Object
Set row = table.getElementsByTagName("tr")(r)
html2.body.innerHTML = "<body> <table>" & row.outerHTML & "</table></body> "
If html2.querySelectorAll("[colspan='2']").Length = 0 Then
outputRow = outputRow + 1: outputColumn = 1
For c = 0 To row.getElementsByTagName("td").Length - 1
results(outputRow, outputColumn) = row.getElementsByTagName("td")(c).innerText
outputColumn = outputColumn + 1
Next
End If
Set row = Nothing
Next
results = Application.Transpose(results)
ActiveSheet.Cells(1, 1).Resize(UBound(results, 1), UBound(results, 2)) = results
End Sub