2017-02-13 70 views
0

我发现了许多类似的问题,但解决方案都是特定于正在处理的页面。我试图从下拉列表中选择一个值,然后触发事件处理程序来重置页面。我不是最擅长使用HTML,我无法确定如何在为下拉菜单指定值后获取页面更新。这是我有:使用VBA在IE中触发事件处理程序

Dim IE As Object 
Dim IECollection As Object 

    Set IE = CreateObject("InternetExplorer.Application") 
     IE.Visible = True 
     IE.navigate "https://www.theocc.com/webapps/historical-volume-query" 

    Do While IE.busy 
     Application.Wait DateAdd("s", 1, Now) 
    Loop 

    Set IECollection =IE.Document.getElementsByName("historicalVolumeSearch.reportType") 
    i = 0 
    While i < IECollection.Length 
     If IECollection(i).Name = "historicalVolumeSearch.reportType" Then 
      IECollection(i).Value = "PC" 
     End If 
    i = i + 1 
    Wend 

我不知道要从页面源代码下一步调用,以使其更新。

谢谢。

+1

会更容易使用网页中列出的选项:https://www.theocc.com/market-data/batch-processing.jsp –

+0

@TimWilliams不幸的是我需要的数据是不容易提取从批处理报告。还有其他建议吗? – amdopt

回答

0

在这里回答我自己的问题。我离开了这几个星期,然后回到它,答案就在我面前。我把我的上面的代码改为下面的代码。按我想要的方式工作,并允许我存储HTML并提取需要的数据。

Dim IE As Object 
Dim IECollection As Object 
Dim IECollection2 As Object 
Dim IEElement As Object 
Dim dt As String 

Set IE = CreateObject("InternetExplorer.Application") 
    IE.Visible = False 
    IE.navigate "https://www.theocc.com/webapps/put-call-ratio" 

Do While IE.busy Or IE.ReadyState <> 4 
    Application.Wait DateAdd("s", 1, Now) 
Loop 

     For i = 1 To UBound(arrDates) 'an array containing a list of dates 
     dt = arrDates(i, 1) 
     Set IECollection = IE.Document.getElementsByName("putCallDate") 
      IECollection(0).Value = dt 
      IECollection(0).Select 

     Set IECollection2 = IE.Document.getElementsByTagName("form") 
      j = 1 
      While j < IECollection2.Length 
       If IECollection2.Item(j).Name = "commandForm" Then 
        Set IEElement = IECollection2.Item(j) 
        IEElement.submit 
       End If 
      j = j + 1 
      Wend 

     Do While IE.busy Or IE.ReadyState <> 4 
      Application.Wait DateAdd("s", 1, Now) 
     Loop 
     'other code in here that stores the HTML as a string and scrapes out data 
     Next i 
相关问题