Macro / VBA可以从www.Eppraisal.com获取值

问题描述 投票:1回答:1

我需要使用Excel宏从www.Eppraisa.com获取一些值。

但是我不知道PropID的值是什么。这就是为什么宏适用于URL1而不适用于URL2的原因,因为我认为URL2具有错误的propID

Const URL1 As String = "http://www.eppraisal.com/home-values/property_lookup_eppraisal?a=1122%20E%20Loyola%20Dr&z=85282&propid=42382460"

Const URL2 As String = "http://www.eppraisal.com/home-values/property_lookup_eppraisal?a=19732%20E%20Reins%20Rd&z=85142&propid=31402642"

Sub xmlHttp()
    Dim xmlHttp As Object
    Set xmlHttp = CreateObject("MSXML2.XMLHTTP")

    ' This works
    xmlHttp.Open "GET", URL1, False

    ' But doesn't work for below url :(
    'xmlHttp.Open "GET", URL2, False

    xmlHttp.setRequestHeader "Content-Type", "text/xml"


    xmlHttp.send

    Dim ieDom As New HTMLDocument
    Dim html As Object
    Set html = CreateObject("htmlfile")
    html.body.innerHTML = xmlHttp.responseText
    Debug.Print html.body.innerHTML
    ieDom.body.innerHTML = xmlHttp.responseText

    For Each ieInp In ieDom.getElementsByTagName("p")
        If ieInp.className = "ColorAccent6 FontBold FontSizeM Margin0 Padding0" Then
            strEppraisalValue = ieInp.innerText
        ElseIf ieInp.className = "FontSizeA Margin0 DisplayNone HighLow" Then
            strEppraisalHighLow = ieInp.innerText
        End If
    Next End Sub
vba excel-vba web-scraping msxml xmlhttprequest
1个回答
2
投票

使用Mozilla Firefox和Firebug,您可以识别请求和响应。

下面的步骤适用于您进行的任何搜索。

1将以下URL复制到Firefox浏览器。

http://www.eppraisal.com/home-values/property/1122-e-loyola-dr-tempe-az-85282-42382460/

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9UeW9LTi5wbmcifQ==” alt =“在此处输入图像描述”>

2打开FireBug,然后查找以下请求。转到网络选项卡> XHR,如下图所示。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9WbE9KVS5wbmcifQ==” alt =“在此处输入图像描述”>

3展开节点并转到“参数”选项卡。它显示了与GET请求一起需要的所有输入参数。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9GVXVYcC5wbmcifQ==” alt =“在此处输入图像描述”>。

4最后,我们可以在“响应”选项卡中看到来自服务器的响应。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9CaGNQSS5wbmcifQ==” alt =“在此处输入图像描述”>

© www.soinside.com 2019 - 2024. All rights reserved.