使Web Scraper操作从登录页面打开的弹出页面

时间:2015-09-03 01:42:25

标签: vba bots scrape

我的代码打开一个页面并开始完成它。然后单击一个按钮,弹出需要完成的弹出屏幕。但是,我不确定如何使我的代码访问弹出屏幕。任何帮助将不胜感激!

这是我的代码:

Sub Van()

Dim IE As Object

Set IE = CreateObject("InternetExplorer.Application")

IE.navigate ("website")

IE.Visible = True

Do
DoEvents
Loop Until IE.readystate = 4

Set d = IE.document

'Code clicks on buttons and dropdowns

Application.Wait (Now + TimeValue("00:00:03"))

d.GetElementbyid("caravanMake").Value = "JAY"


End Sub

1 个答案:

答案 0 :(得分:1)

这对我来说是设置弹出窗口中第一个下拉列表的值:

'...
Application.Wait (Now + TimeValue("00:00:03"))

Set IE2 = GetIE("https://secure.apia.com.au/NASApp/apia/CRQuoteServlet?" & _
                 "pageAction=openModelSelectionWindow&currentSequenceNumber=")

IE2.document.getElementsByTagName("select")(0).Value = "JAY"
'etc

查找具有给定URL的打开窗口的功能:

'Find an IE window with a matching URL
'Assumes no frames.
Function GetIE(sAddress As String) As Object

Dim objShell As Object, objShellWindows As Object, o As Object
Dim retVal As Object, sURL As String


    Set retVal = Nothing
    Set objShell = CreateObject("Shell.Application")
    Set objShellWindows = objShell.Windows

 'see if IE is already open
    For Each o In objShellWindows
        sURL = ""
        On Error Resume Next
        sURL = o.LocationURL
        On Error GoTo 0
        If sURL <> "" Then
            'Debug.Print sURL
            If sURL = sAddress Then
              Set retVal = o
              Exit For
            End If
        End If
    Next o

Set GetIE = retVal
End Function