Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
excel数据获取的网站_Excel_Vba - Fatal编程技术网

excel数据获取的网站

excel数据获取的网站,excel,vba,Excel,Vba,请任何人使用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 =

请任何人使用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

试试这样的方法

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

谢谢

我添加了图片太好了!我现在看到了。我会循环所有
span
元素,寻找一个内部文本为“Property Address”的元素,然后设置一个标志,以便在下一次迭代(下一个span)中,我可以获取下一个span的内部文本。我试过了,但对我不起作用。你能告诉我你在这里可以使用的确切代码吗?