首页 > 解决方案 > 将数据拉到excel中的工作簿

问题描述

尝试从网站抓取数据时遇到问题。这是运行时错误“424”:需要对象我的代码:

Option Explicit
Sub GetData()

Dim IE As New SHDocVw.InternetExplorer

IE.Visible = True

IE.Navigate "abc.com"

Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop

IE.Document.forms("vinSearchForm").elements("vin").Value = 
"******"
IE.Document.forms("vinSearchForm").elements("vinSearch").Click
Sheets("Sheet1").Select
Range("A10").Select 
IE.Document.forms("vinSummaryForm").elements
("test_vinSummary_carSpecification_$4").Value = Range("A10").Value

End Sub

我想要的是在范围(“A10”)中显示结果“2004*********”。请相应地帮助我。谢谢。

标签: excelvba

解决方案


虽然不是最好的方法,但应该为你工作

Option Explicit
Sub Autocheck()

    Dim IE As New SHDocVw.InternetExplorer

    IE.Visible = True

    IE.Navigate "Autocheck.com"

    Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy
        DoEvents
    Loop

    Application.Wait Now + TimeSerial(0, 0, 5)
    IE.Document.forms("vinSearchForm").elements("vin").Value = "JTDKB22U140021007"
    IE.Document.forms("vinSearchForm").elements("vinSearch").Click

    Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy
        DoEvents
    Loop

    Application.Wait Now + TimeSerial(0, 0, 5)
    Range("A10").Value = Split(IE.Document.getelementbyid("test_vinSummary_carSpecification_$4").innerText, vbNewLine)(1)

    IE.Quit
    Set IE = Nothing

End Sub

推荐阅读