我已经在vba中创建了一个与硒结合使用的脚本,以解析表第一列中所有可用的链接,同时单击底部的下一页按钮,并浏览每个链接以访问其内页。为了从那里刮标题。但是,我希望我的脚本继续执行此操作,直到没有其他下一页按钮可供点击为止。
我尝试过:
Sub FetchTitleFromInnerPage()
Dim driver As New ChromeDriver, post As Object, key As Variant
Dim idic As New Scripting.Dictionary, npage As Object
driver.get "https://www.marketscreener.com/stock-exchange/shares/Oceania-7/Australia-147/"
Do
For Each post In driver.FindElementsByCss("#ZBS_restab_2b td > a[href]", timeout = 10000)
idic(post.Attribute("href")) = 1
Next post
For Each key In idic.Keys()
driver.get key
'haven't written the code for parsing title as it produces duplicates
Next key
Set npage = driver.FindElementByCss("a.nPageEndTab[title^='Next']", timeout = 10000)
If Not npage Is Nothing Then
driver.ExecuteScript "arguments[0].click();", npage
Else:
Exit Do
End If
Loop
Stop
End Sub
上面的脚本似乎产生了很多重复,并且发生(我想)只是因为该脚本需要在单击下一页按钮后等待下一页元素可用。
在单击下一页按钮时如何导航到表格的每个链接的内页?