如何根据在搜索框中输入的内容单击不断更改的链接

时间:2015-08-19 17:53:55

标签: excel vba excel-vba web-crawler

我无法点击页面中的链接,因为在每个搜索框中输入一个数字后链接会不断变化。我尝试了几个VBA代码,但无法实现它。



<A href="../finding/data?data=ALL&amp;version=0&amp;edocid=0&amp;ssid=05BDPUSPHL&amp;refnum=15Q100595&amp;defaultemail=abc@abc.com&amp;snpid=15834667918&amp;servicecd=E" target=_blank>Data</A>
&#13;
&#13;
&#13;

Sub try()
    Dim ie As Object
    Dim MyHTML_Element As IHTMLElement
    Dim MyURL As String
    Dim MyURLSer As String
    Set ie = CreateObject("InternetExplorer.Application")
    On Error GoTo Err_Clear
    MyURL = "[http://test.com/login][1]"
    Set MyBrowser = New InternetExplorer
    MyBrowser.Silent = True
    MyBrowser.navigate MyURL
    MyBrowser.Visible = True
    Do
    Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
    Set HTMLDoc = MyBrowser.document
    HTMLDoc.all.j_username.Value = "User" 'Enter your email id here
    HTMLDoc.all.j_password.Value = Password'Enter your password here
    For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
        If MyHTML_Element.Type = "button" Then MyHTML_Element.Click: Exit For
    Next
    On Error GoTo Err_Clear
    MyURL = "http://test.com/home"
    Set MyBrowser = New InternetExplorer
    MyBrowser.Silent = True
    MyBrowser.navigate MyURL
    MyBrowser.Visible = True
    Do
    Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
    Set HTMLDoc = MyBrowser.document
    HTMLDoc.all.searchKeyword.Value = "223645" 'Enter your email id here
    Call HTMLDoc.parentWindow.execScript("submitSearch();", "javascript")
    For Each l In ie.document.getElementsByTagName("a")
        If l.className = "docCheckBox" Then l.Click: Exit For
    Next
    Err_Clear:
    If Err <> 0 Then
        Err.Clear
        Resume Next
    End If
End Sub

0 个答案:

没有答案