从网页中的每个链接获取数据以获得优秀

时间:2012-12-17 15:58:15

标签: vba

我正在尝试从网页上获取数据。(某些链接)

在该网页中,客户提出了许多门票(链接)。我需要浏览每个链接并从每个票证中获取一些特定数据(链接)。

我的程序需要点击每个评论链接并从每个链接获取一些数据。

我的程序成功选择了第一张票据数据但并非全部(点击第一个链接并成功获取第一个链接数据然后它会引发错误)。

它抛出错误(访问错误)

抱歉,我的代码很庞大

Option Explicit

Sub AVS()
Dim ie As InternetExplorer
Dim iedoc As HTMLDocument
Dim innerString As String
Dim ttext As Integer
Dim avsHtmlTable As Object
Dim links As HTMLAnchorElement
Dim link As Object
Dim lRow As Integer

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "https://apj-i.svcs.hp.com/itam-av1/"

Do While ie.Busy
    DoEvents
Loop

Do Until ie.ReadyState = READYSTATE_COMPLETE
    DoEvents
Loop

Set iedoc = ie.Document
With iedoc.forms("Login")
    .all.Item("USER").Value = "Mail id goes here"
    .all.Item("PASSWORD").Value = "pw goes here"
    .submit
End With

Do While ie.Busy
    DoEvents
Loop

Do Until ie.ReadyState = READYSTATE_COMPLETE
    DoEvents
Loop

With iedoc.forms("aspnetForm")
    .all.Item("ctl00$conNavBar$acpAssets_content$btnAssets-ExceptionSearch").Click
End With

Do While ie.Busy
    DoEvents
Loop

Do Until ie.ReadyState = READYSTATE_COMPLETE
    DoEvents
Loop

With iedoc.forms("aspnetForm")
    .all.Item("ctl00$conMainPageContent$txtMaxRows").Value = 100
    .all.Item("ctl00$conMainPageContent$rblStatus").Item(4).Checked = True
    .all.Item("ctl00$conMainPageContent$btnAssetExceptionSearch").Click
End With

Do While ie.Busy
    DoEvents
Loop

Do Until ie.ReadyState = READYSTATE_COMPLETE
    DoEvents
Loop

With iedoc.forms("aspnetForm")
    innerString = .innerText
    ttext = InStr(innerString, "There are no results found for this query")
    If Not ttext = 0 Then
        MsgBox "There are no Tickets are there in AVS - Exception ", vbInformation, "AVS-Exception"
    Else
        ''ctl00_conMainPageContent_grdAssetExceptionSearchResults
        Set avsHtmlTable = iedoc.getElementsByTagName("a")

        For Each link In avsHtmlTable
            If link.innerHTML = "Review" Then
                link.Click
                Do While ie.Busy
                    DoEvents
                Loop
                Do Until ie.ReadyState = READYSTATE_COMPLETE
                    DoEvents
                Loop
                With Sheets("AVS")
                set iedoc=ie.document
                    lRow = .Range("A10000").End(xlUp).Row
                    > ##        ' error throws here
                    Range("A" & lRow).Value = iedoc.getElementById("ctl00_conMainPageContent_ddlAssignment").Value
                End With
            End If
        Next link
    End If
End With

End Sub

很抱歉..由于我的第一篇帖子无法附加图片。

0 个答案:

没有答案