从网站中提取信息

时间:2016-06-07 12:19:01

标签: html vba excel-vba excel

早上好,

我之前编写过宏来使用Excel工作表中的信息从网站中提取信息。我使用带有URL的Get命令来获取我正在搜索的特定信息,就像将ID放在URL的末尾一样简单。这个并不容易。我不能把ID放在URL的末尾,这是我的VBA知识的范围,到目前为止我还没有成功。该网站是https://www.nctracks.nc.gov/publicPortal/provider/PractitionerSearch.action,我如何从excel向网站提交NPI?我知道如何筛选HTML以获取信息,而不是如何在那里导航。任何帮助将不胜感激,谢谢!

1 个答案:

答案 0 :(得分:1)

基本上使用IE中的开发者工具(f12)并使用ctrl + B找到有问题的元素你需要调整providerNPI的值,但是你可以使用这样的东西:

Private IE As Object
Private ieDoc As Object
Const Readystate_Complete As Long = 4

Sub GetData()
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.navigate "https://www.nctracks.nc.gov/publicPortal/provider/PractitionerSearch.action"
    ieBusyLoop
    Set ieDoc = IE.document
    ieDoc.getElementbyID("providerNPI").Value = "1234567890"
    IeClickID ("search")
    Set ieDoc = Nothing
End Sub
Private Sub IeClickID(ByVal ElId$)
    ieDoc.getElementbyID(ElId).Click
    OneSecDelay
    Call ieBusyLoop
End Sub
Private Sub OneSecDelay()
        waitTime = Now + TimeValue("00:00:01")
        Do Until Now >= waitTime: DoEvents: Loop
End Sub
Private Sub ieBusyLoop()
    Do While IE.busy: DoEvents: Loop
    Do Until IE.readystate = Readystate_Complete: DoEvents: Loop
End Sub