我正在尝试从网页获取数据。(一些链接)
在那个网页上,有很多客户提出的票(链接)。我需要浏览每个链接并从每个票证(链接)中获取一些特定数据。
我的程序需要单击每个评论链接并从每个链接中获取一些数据。
我的程序成功地选择了第一个票数据但不是全部(单击第一个链接并成功获取第一个链接数据然后它会抛出错误)。
它抛出错误(访问错误)
对不起,我的代码很大
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
抱歉.. 由于我的第一篇文章,无法附上图片。