excel vba IE对象

时间:2016-06-25 10:40:58

标签: vba excel-vba excel

我想从此页https://search.rpxcorp.com/advanced_search/search_litigations#grouped=false&searchq=%221%3A2015-cv-00014%22&page=1&sub_page=1

获取结果

但是得到错误:

got this popup

当我将光标移动到“ObjResult5”时单击Debug后,它显示ObjResult5 =“Nothing”

got this popup

我的宏:

Sub getDataIE_Basic()
Dim totalResults As Long
Dim RowBasic As Long
totalResults = 2-1
RowBasic = 2

Set Sheet_OutputBasic = Worksheets("Output - Basic Data")
Set objIEBrowser = CreateObject("InternetExplorer.Application")

objIEBrowser.Visible = True
Dim url As String
url = "https://search.rpxcorp.com/advanced_search/search_litigations#grouped=false&searchq=%221%3A2015-cv-00014%22&page=1&sub_page=1"

objIEBrowser.navigate url

Do
    DoEvents
Loop Until objIEBrowser.readyState = READYSTATE_COMPLETE

Call FnWait(5)

Set Doc = objIEBrowser.document

For Results = 0 To totalResults

Set objResultMain = Doc.getElementById("search_results_replaced_content")
Set objResult = objResultMain.getElementsByTagName("Div")(0)
Set objResult2 = objResult.getElementsByTagName("Div")(1)
Set objResult3 = objResult2.getElementsByTagName("Div")(2)
Set objResult4 = objResult3.getElementsByTagName("Div")(1)
Set objResult5 = objResult4.getElementsByTagName("table")(0)
Set objResult6 = objResult5.getElementsByTagName("tbody")(0)
Set objResult7 = objResult6.getElementsByTagName("tr")(0)

FileDate = objResult7.getElementsByTagName("td")(0).innerText
CaseName = objResult7.getElementsByTagName("td")(1).innerText
CaseNo = objResult7.getElementsByTagName("td")(2).innerText
FilJurisdiction = objResult7.getElementsByTagName("td")(3).innerText
Status = objResult7.getElementsByTagName("td")(4).innerText

Sheet_OutputBasic.Cells(RowBasic, 1) = FileDate
Sheet_OutputBasic.Cells(RowBasic, 2) = CaseName
Sheet_OutputBasic.Cells(RowBasic, 3) = CaseNo
Sheet_OutputBasic.Cells(RowBasic, 4) = FilJurisdiction
Sheet_OutputBasic.Cells(RowBasic, 5) = Status

RowBasic = RowBasic + 1

Next Results

End Sub
Function FnWait(intTime)

newHour = Hour(Now())

newMinute = Minute(Now())

newSecond = Second(Now()) + intTime

waitTime = TimeSerial(newHour, newMinute, newSecond)

Application.Wait waitTime

End Function

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

您应该使用firefox开发人员工具的“网络”标签查看该页面(请参阅下图)。

您收到错误的原因是因为首次加载页面时没有<table ...>元素。有一个第二个调用(POST)到search_litigations,其中包含您尝试访问的表。

您需要确定正确的调用以获取所需的数据。

enter image description here