好的,对不起伙计......我设法找出了点击"下一个结果"按钮并将其循环回来以提取相同的数据,然后单击"下一个结果"按钮并拉出相同的数据...依此类推,直到......以及我遇到问题的地方。我一直得到一个"对象需要"我的"循环直到"声明......我尝试了许多不同的解决方法,切换到变量等,但仍然遇到错误。基本上我只想循环停止一次"下一个结果"按钮不再可用(当没有更多数据需要时,这显然会发生)。
这是导致问题的VBA部分......
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long
Set TDelements = IE.document.getElementsByTagName("tr")
r = 0
Do
Application.Wait Now + TimeValue("00:00:03")
For Each TDelement In TDelements
If TDelement.className = "searchActivityResultsContent" Then
Sheet1.Range("E1").Offset(r, 0).Value = TDelement.ChildNodes(8).innerText
r = r + 1
ElseIf TDelement.className = "searchActivityResultsContent" Then
Sheet1.Range("E1").Offset(r, 0).Value = TDelement.ChildNodes(8).innerText
r = r + 1
End If
Next
Application.Wait Now + TimeValue("00:00:02")
Set elems = IE.document.getElementsByTagName("input")
For Each e In elems
If e.Value = "Next Results" Then
e.Click
Exit For
End If
Next e
Loop Until e.Value <> "Next Results"
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
IE.Quit
这里是我所指的按钮的HTML代码......
<table class="contentTable" align="center">
<tr class="contentTableTR">
<form name="scrollResultListForm" method="post" action="/scrollTransactionsList.do" onsubmit="return isBusy();">
<input type="submit" name="action" value="Next Results" onmouseover="showComment(event,'Display next results')" onmouseout="hideComment()" class="formButton">
<input type="submit" name="action" value="Last Page" onmouseover="showComment(event,'Goto last result page')" onmouseout="hideComment()" class="formButton">
</form>
</tr>
</table>
答案 0 :(得分:0)
按钮的示例代码: 尝试使用最里面的标签类型,例如它是否在&#34; a&#34;在div中标记,使用&#34; a&#34;
Dim aTag, someTags
Set someTags = IE.Document.getElementsByTagName("a")
For Each aTag In someTags
If InStr(aTag.innerText, "NextResults") Then
aTag.Click
Exit For
End If
Next aTag