您可以从 URL 加载 XML DOM 文档,然后使用其方法从选定节点访问文本。以下示例使用 XPath 来识别节点,但也可以使用其他方法getElementsByTagName
:SelectNodes
; 等等
我用后期绑定编写了这个示例。在探索文档方法和属性时,您可能更喜欢使用早期绑定进行开发……为Microsoft XML设置参考。
Dim strUrl As String
Dim strXPathBase As String
' early binding requires reference to Microsoft XML
'Dim objDoc As MSXML2.DOMDocument
'Set objDoc = New MSXML2.DOMDocument
' late binding, no reference required
Dim objDoc As Object
Set objDoc = CreateObject("MSXML2.DOMDocument")
strUrl = "https://isbndb.com/api/books.xml" & _
"?access_key=NSOY388Z&results=texts" & _
"&index1=isbn&value1=0007102968"
objDoc.async = False
objDoc.Load strUrl
strXPathBase = "//ISBNdb/BookList/BookData/"
Debug.Print "Title: " & _
objDoc.SelectSingleNode(strXPathBase & "Title").Text
Debug.Print "Publisher: " & _
objDoc.SelectSingleNode(strXPathBase & "PublisherText").Text
Set objDoc = Nothing