网站以出色的数据获取

时间:2018-06-19 13:47:25

标签: excel-vba vba excel

任何人都可以使用VBA帮助从网站获取数据到excel,我需要在excel单元格中找到属性地址:

Option Explicit

Sub test()

Dim ie As New InternetExplorer

ie.navigate "xyz.org"
ie.Visible = True
Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
    Set doc = ie.document
    ie.document.all("input-search-field").Value = Range("b1").Value
Dim obj     As Object
    For Each obj In ie.document.getElementsByTagName("BUTTON")
        If obj.className = "btn btn-default search-button" Then
            obj.Click
            Exit For
    Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE
    Dim isPropertyAddr  As Boolean
    isPropertyAddr = ie.document.getElementById("LoanObject").ie.document.getelementbytagname("SPAN")
    isPropertyAddr = True
    Debug.Print ie.document.getattributes("classname"), ie.document.getattributes("tagname")

    MsgBox obj.innerText

dom code

1 个答案:

答案 0 :(得分:0)

尝试这样的事情

IsAddressFound = False
For Each obj In ie.document.getElementById("LoanObject").getElementsByTagname("SPAN")
    If InStr(obj.Innertext, "Property Address") > 0 Then
        IsAddressFound = True
    End If
    If IsAddressFound Then
        Debug.Print obj.Innertext 'Your address populates here
        IsAddressFound = False
    End If
Next

谢谢