我通常使用它来单击网站上的下一页,它工作正常。但是这次我很难解决,因为它是 ul Class
然后是 li class
.我尝试了几种变体,来自 .getAttribute
至.getElementsByTagName
,但是我无法解决'
我尝试添加子点头,以便它选择正确的 li 但似乎没有任何效果,我被卡住了。
有人可以看看吗,总是提前谢谢
这是 HTML
点击下一页的代码
Searches Number of Pages entered in Sheet20
If pageNumber >= Replace(Worksheets("Sheet20").Range("J9").Value, "", "+") Then Exit Do
On Error Resume Next
Set nextPageElement = Html.getElementsByClassName("a-pagination")(0) '''' THIS LINE ''''''
If nextPageElement Is Nothing Then Exit Do
nextPageElement.Click 'next web page
Do While objIE.Busy = True Or objIE.readyState <> 4
Loop
Set Html = objIE.document
pageNumber = pageNumber + 1
'DoEvents
最佳答案
以下任一解决方案都应该有效:
Sub InitiateClick()
Dim IE As New InternetExplorer
Dim nextPage As Object
With IE
.Visible = True
.navigate "https://www.amazon.com/s?k=phones&page=2&qid=1612460431&ref=sr_pg_1"
Do While .Busy = True Or .readyState <> 4: DoEvents: Loop
'if it still fails to click on that buttton, make sure to put some delay in this line
' Set nextPage = .document.getElementsByClassName("a-pagination")(0).getElementsByClassName("a-last")(0).getElementsByTagName("a")(0)
Set nextPage = .document.querySelector(".a-pagination > li.a-last > a")
If Not nextPage Is Nothing Then
nextPage.Click
End If
End With
End Sub
关于html - 网页导航 点击下一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66051816/