Вам нужно больше, чем вы получаете от следующего (Примечание: здесь я читаю ваш HTML из ячейки в HTML-документ. Вы сделали бы это обычным способом.). Очевидно, что он не очень надежный, но я не думаю, что вы просто зацикливаете строки, затем столбцы внутри, и делаете HTMLCell.innerText
① Ранняя оценка:
Код:
Option Explicit
Public Sub GetTableInfo()
Dim html As HTMLDocument
Set html = New HTMLDocument
html.body.innerHTML = [A1].Text '<== You would obtain in normal way. I just read your HTML in from sheet.
Debug.Print "Case number: " & html.querySelectorAll("table tr td[class=""item_1""] input")(0).Value
Debug.Print "licence number - city: " & html.querySelectorAll("table tr td[class=""item_1""] input")(1).Value
Debug.Print "licence number - letter: " & html.querySelectorAll("table tr td[class=""item_1""] input")(2).Value
Debug.Print "licence number - number: " & html.querySelectorAll("table tr td[class=""item_1""] input")(3).Value
Debug.Print "participant number: " & html.querySelectorAll("table tr td[class=""item_1""] option[selected=""selected""]")(0).innerText
Debug.Print "type of vehicle (own definition): " & html.querySelectorAll("table tr td[class=""item_1""] option[selected=""selected""]")(1).innerText
End Sub
② Версия с поздним связыванием для OP:
Не глядя на более широкий контекст HTML, здесь есть немного хрупкий фрагмент кода:
Option Explicit
Public Sub GetTableInfo()
Dim html As Object
Set html = CreateObject("htmlfile")
html.body.innerhtml = [A1].Text '<== You would obtain in normal way. I just read your HTML in from sheet.
html.getElementsByTagName ("table")
Dim b As Object
Set b = html.getElementsByTagName("table")(0).getElementsByTagName("input")
Debug.Print "Case number = " & b(0).Value
Debug.Print "licence number - city: = " & b(1).Value
Debug.Print "licence number - letter = " & b(2).Value
Debug.Print "licence number - number = " & b(3).Value
Dim c As Object
Set c = html.getElementsByTagName("table")(0).getElementsByTagName("option")
Dim i As Long, n As Long
For i = 0 To c.Length - 1
If InStr(c(i).outerHTML, "selected value=") > 0 Then
n = n + 1
If n = 1 Then
Debug.Print "participant number: " & c(i).innerText
ElseIf n = 2 Then
Debug.Print "type of vehicle (own definition) " & c(i).innerText
End If
End If
Next i
End Sub
Выход:
Это то же самое, что и с .querySelector.
К сожалению, 豫 выходит как?
③ Разбор HTML:
Вы также можете анализировать HTML. Приспособьте к своему фактическому полному HTML, но вот как вы можете сделать это с помощью предоставленного фрагмента:
Dim arr() As String
arr = Split([A1].Text, "class=""item_1""")
Debug.Print "Case number = " & Split(Split(arr(1), "value=")(1), Chr(32))(0)
Debug.Print "participant number: " & Split(Split(Split(arr(2), "value=")(2), "selected=""selected"">")(1), "<")(0)
Debug.Print "licence number - city: = " & Split(Split(arr(3), "value=")(1), Chr(32))(0)
Debug.Print "licence number - letter = " & Split(Split(arr(4), "value=")(1), Chr(32))(0)
Debug.Print "licence number - number = " & Split(Split(arr(5), "value=")(1), Chr(32))(0)
Debug.Print "type of vehicle (own definition) " & Split(Split(arr(6), "selected=""selected"">")(1), "<")(0)