首页 > 解决方案 > 从单页 Web 应用程序进行 Vba Web 抓取

问题描述

大家好,任何人都可以帮助我,我必须在 InputBox 中输入一些值,然后单击“搜索”按钮。根据该 InputBox 值数据显示在同一页面中而无需更改其 URL。我制作了一个代码,它在输入框中输入了一个值,但是当代码点击搜索按钮时,弹出窗口显示输入框为空

检查 InputBox 的元素

<input id="u_edi_claim_key0" placeholder="" ng-model-options="{ allowInvalid: true }" name="u_edi_claim_key0" type="text" class="form-control input-sm ng-valid ng-valid-maxlength ng-touched ng-dirty ng-valid-parse ng-empty" ng-model="searchController.Obj[tab.id+':'+data.displayID]" capitalize="u_fln_dcc">

检查 SearchButton 的元素

<button type="submit" id="Search" class="btn btn-primary btn-sm ng-binding" data-toggle="tooltip" ng-click="searchController.performSearch()" ng-disabled="searchController.callInProgress || searchController.searchForm.u_edi_claim.$invalid" title="Click this button to perform the search.">

    Sub macro()
    Dim a As String
    Dim IE As InternetExplorerMedium
    Set IE = New InternetExplorerMedium
    Dim Ist As IHTMLElementCollection
    Dim i As IHTMLElement
    IE.Visible = True
    a = "https://doc30-ui.uhg.com/doc30-ui/search"
    IE.navigate a
    
    Do While IE.ReadyState <> READYSTATE_COMPLETE
    Loop
    Application.Wait Now + TimeValue("00:00:3")
    
    Dim DOC  As New HTMLDocument
    Set DOC = IE.document
    Set Ist = DOC.getElementsByTagName("input")
    For Each i In Ist
        If i.ID = "u_edi_claim_key0" Then
           i.Focus
           i.Select
           i.Value = 66827839
        End If
        DOC.getElementById("Search").Click
    Next
    MsgBox "done"
    End Sub

标签: javascriptangularjsvbaweb-scrapingsingle-page-application

解决方案


 Sub macro()
    Dim a As String
    Dim IE As InternetExplorerMedium
    Set IE = New InternetExplorerMedium
    Dim Ist As IHTMLElementCollection
    Dim i As IHTMLElement
    IE.Visible = True
    a = "https://doc30-ui.uhg.com/doc30-ui/search"
    IE.navigate a
    
    Do While IE.ReadyState <> READYSTATE_COMPLETE
    Loop
    Application.Wait Now + TimeValue("00:00:3")
    
    Dim DOC  As New HTMLDocument
    Set DOC = IE.document
    Set Ist = DOC.getElementsByTagName("input")
    For Each i In Ist
        If i.ID = "u_edi_claim_key0" Then
           i.Focus
           i.Select
           i.Value = 66827839
           Exit For
           Application.Sendkeys "~"
        End If
        
    Next
    Application.Sendkeys "~"
    MsgBox "done"
    End Sub

推荐阅读