0
表的HTML是:網頁抓取一張桌子下面搜索循環
<TABLE border="1" width="100%">
<TR class="row0">
<TD style="width: 30%"><strong>TITLE</strong></TD>
<TD style="width: 40%">UNIQUE</TD>
<TD style="width: 15%"><strong>BU Assigned</strong></TD>
<TD style="width: 15%">REMOVED</TD>
</TR>
<TR class="row1">
<TD style="width: 30%"><strong>Account Number</strong></TD>
<TD style="width: 40%">TARGET INFORMATION</TD>
<TD style="width: 15%"><strong>BU Logged</strong></TD>
<TD style="width: 15%">REMOVED</TD>
</TR>
<TR class="row0">
<TD style="width: 30%"><strong>3rd Party Reference</strong></TD>
<TD style="width: 40%">REMOVED</TD>
<TD style="width: 15%"><strong>Date Received</strong></TD>
<TD style="width: 15%">REMOVED</TD>
</TR>
<TR class="row1">
<TD style="width: 30%"><strong>Subject</strong></TD>
<TD style="width: 40%">REMOVED</TD>
<TD style="width: 15%"><strong>Date Logged</strong></TD>
<TD style="width: 15%">REMOVED</TD>
</TR>
<TR class="row0">
<TD style="width: 30%"><strong>Reason</strong></TD>
<TD style="width: 40%">REMOVED</TD>
<TD style="width: 15%"><strong>Last Action Date</strong></TD>
<TD style="width: 15%">REMOVED</TD>
</TR>
<TR class="row1" >
<TD style="width: 30%"><strong>Status</strong></TD>
<TD style="width: 40%">REMOVED</TD>
<TD style="width: 15%"><strong>Date Resolved</strong></TD>
<TD style="width: 15%">REMOVED</TD>
</TR>
</TABLE>
我正在尋找通過在頁面中的所有表,試圖拉「目標信息」定位「UNIQUE」之後,我認爲應該在行(0).Cells(1)中,但是這會給我帶來運行時錯誤91-對象變量或塊變量未設置。
但是,當我搜索行(0).Cells(0)爲「TITLE」時,代碼將查找表並且我可以愉快地進行。任何人都知道這個方法嗎?我曾嘗試將單元格號一直改爲10,以防萬一有些空單元格我沒有注意到。注意:可能有多個表,其中0,0具有相同的標題,唯一唯一的字段是UNIQUE,它是從我的電子表格中獲得的。我使用的代碼如下。
Private Sub test()
Dim IE As Object
Dim RowCnt As Integer
Dim CIS, AN, CR As String
RowCnt = 2
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
Do Until Workbooks("My Book").Worksheets("My Sheet").Range("A" & RowCnt).Value = ""
CIS = Workbooks("My book").Worksheets("My sheet").Range("C" & RowCnt).Value
IE.Navigate "First part" & CIS & "Second Part"
While IE.Busy
DoEvents
Wend
Dim tbls, tbl
Set tbls = IE.Document.getElementsByTagName("TABLE")
CR = Workbooks("My book").Worksheets("My sheet").Range("A" & RowCnt).Value
For Each tbl In tbls
If tbl.Rows(0).Cells(1).innertext = CR Then
AN = tbl.Rows(1).Cells(1).innertext
Exit For
End If
Next
RowCnt = RowCnt + 1
Loop
End Sub