解析来自 HTML 响应的行 Excel VBA
Parse line from HTML response in Excel VBA
我正在寻找解析 Excel VBA 中的 'WinHttpRequest' 响应以从 HTML 响应中提取特定行。这是 HTTP 请求的代码。
Function getSetName(ByVal setNUMBER As String) As String
Dim oRequest As Object
Dim xmlResponse As String
Dim setDescription As String
Dim setName As String
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "https://brickset.com/sets/75192" '& setNUMBER
oRequest.Send
xmlResponse = oRequest.ResponseText
'parse xml response here
getSetName = setName
End Function
我希望仅将带有 HTML 标记 'meta name=""description""' 的行解析为一个字符串,稍后我将从中提取信息。
任何关于如何解析这一行的帮助或指导将不胜感激。
尝试
Sub Test_GetSetName()
Debug.Print GetSetName("75192")
End Sub
Function GetSetName(ByVal SetNUMBER As String) As String
Dim html As New MSHTML.HTMLDocument
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", "https://brickset.com/sets/" & SetNUMBER, False
.send
html.body.innerHTML = .responseText
End With
GetSetName = html.querySelector("[name='description']").Content
End Function
我正在寻找解析 Excel VBA 中的 'WinHttpRequest' 响应以从 HTML 响应中提取特定行。这是 HTTP 请求的代码。
Function getSetName(ByVal setNUMBER As String) As String
Dim oRequest As Object
Dim xmlResponse As String
Dim setDescription As String
Dim setName As String
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
oRequest.Open "GET", "https://brickset.com/sets/75192" '& setNUMBER
oRequest.Send
xmlResponse = oRequest.ResponseText
'parse xml response here
getSetName = setName
End Function
我希望仅将带有 HTML 标记 'meta name=""description""' 的行解析为一个字符串,稍后我将从中提取信息。
任何关于如何解析这一行的帮助或指导将不胜感激。
尝试
Sub Test_GetSetName()
Debug.Print GetSetName("75192")
End Sub
Function GetSetName(ByVal SetNUMBER As String) As String
Dim html As New MSHTML.HTMLDocument
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", "https://brickset.com/sets/" & SetNUMBER, False
.send
html.body.innerHTML = .responseText
End With
GetSetName = html.querySelector("[name='description']").Content
End Function