将网站中的数字检索到Excel中

时间:2015-06-15 21:33:47

标签: excel excel-vba vba

从这个网站http://bit.ly/1Ib8IhP

我正在尝试将此号码输入Excel单元格。

Avg. asking price in Bayswater Road:  £1,828,502

有没有办法使用VBA或其他工具?无法使其与网络查询一起使用。

1 个答案:

答案 0 :(得分:2)

以下是可能的解决方案之一:

Option Explicit

Sub RetrieveAvgPrice()
    Dim sUrl, sContent, sPrice
    sUrl = "http://www.zoopla.co.uk/home-values/london/bayswater-road/"
    With CreateObject("MSXML2.XMLHttp")
        .Open "GET", sUrl, False
        .Send ""
        sContent = .ResponseText
    End With
    With CreateObject("VBScript.RegExp")
        .Global = True
        .MultiLine = True
        .IgnoreCase = False
        .Pattern = "Avg\. asking price[\s\S]*?class=""price big"">([\s\S]*?)<"
        sPrice = HtmlSpecialCharsDecode(.Execute(sContent).Item(0).SubMatches(0))
    End With
    MsgBox sPrice
End Sub

Function HtmlSpecialCharsDecode(sText)
    With CreateObject("htmlfile")
        .Open
        With .createElement("textarea")
            .innerHTML = sText
            HtmlSpecialCharsDecode = .Value
        End With
    End With
End Function