通过URL从XML获取信息 [英] Get Information From XML From A URL

查看:91
本文介绍了通过URL从XML获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从此URL中提取信息

I'm trying to extract information from this URL https://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz18hxnbvw0ej_40oka&address=2912%20WEST%201ST%20STREET%20UNIT%201&citystatezip=Jacksonville%20FL%2032254

我要提取的信息是102557,可以从XML URL的这一部分找到:

The information I want to extract is 102557, it can be found from this portion of the XML URL:

<zestimate>
<amount currency="USD">102557</amount>

我正在使用这段代码来提取它,并给我一个对象变量或未设置块变量"的错误消息.

I'm using this code to extract it and its giving me an "Object variable or With block variable not set" error message.

Sub GetInfo2()

    Dim Http As New XMLHTTP60, Html As New HTMLDocument
    Dim lastrow As Long, i As Long
    Dim sdd As String
    Dim add As Variant
    Dim url As Range

    i = 2

    For Each url In Range(Cells(3, "M"), Cells(Rows.Count, "M").End(xlUp))
        With Http
            .Open "GET", url, False
            .send
            Html.body.innerHTML = .responseText
        End With


        sdd = Html.querySelector("span[class='zsg-tooltip-launch_keyword']")(0).innerText
        i = i + 1
        DD.Cells(i, "J") = sdd

    Next url


End Sub


推荐答案

尝试一下,它对我有用.您只需要对其稍作修改即可为您工作...

Try this, it worked for me. You'll just need to modify it slightly to work for you ...

Sub GetInfo2()
    Dim objHttp As XMLHTTP60, objXml As DOMDocument60, strUrl As String

    Set objHttp = New XMLHTTP60
    Set objXml = New DOMDocument60

    strUrl = "https://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz18hxnbvw0ej_40oka&address=2912%20WEST%201ST%20STREET%20UNIT%201&citystatezip=Jacksonville%20FL%2032254"

    With objHttp
        .Open "GET", strUrl, False
        .send
    End With

    If objXml.LoadXML(objHttp.responseText) Then
        Debug.Print objXml.DocumentElement.SelectSingleNode("response/results/result/zestimate/amount").Text
    End If
End Sub

...显然,我将其剥离回了原始调用,以便可以确定具体目标.

... obviously I stripped it back to the raw call so I could target the specifics.

这也可以...

objXml.DocumentElement.SelectSingleNode("//amount").Text

...不过要小心一点.

... just be careful with that one though.

这篇关于通过URL从XML获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆