先生,我得到的问题,以获得数据到excel,我有一些selenium代码,以获得数据从URL最大分页号。以超越一切。
Public Sub URL_Max_Page()
Dim driver As New ChromeDriver
Dim URL As String
'open the page with the URL
URL = "https://www.justdial.com/Rajkot/Software-Companies/page-60"
driver.Get [URL]
'get maximum page number in to excel
MX = driver.FindElementsById("paginationlastPageNum").Text
ActiveSheet.Range("A7") = MX
driver.Quit
End Sub我收到一些错误..我不知道如何让我的代码正常工作

发布于 2020-05-08 20:47:30
不确定,但试试这个
Public Sub URL_Max_Page()
Dim driver As New ChromeDriver, aScriptParts, mx, sURL As String, sResp As String, sScriptPart As String, i As Long
sURL = "https://www.justdial.com/Rajkot/Software-Companies/page-60"
With driver
.Get [sURL]
sResp = .PageSource
aScriptParts = Split(sResp, "<script", , vbTextCompare)
For i = LBound(aScriptParts) + 1 To UBound(aScriptParts)
sScriptPart = Split(aScriptParts(i), "</script", , vbTextCompare)(0)
If InStr(sScriptPart, "paginationPageNum") Then
mx = Split(Split(sScriptPart, "paginationPageNum = ")(1), ";")(0)
Exit For
End If
Next i
Debug.Print mx
.Quit
End With
End Subhttps://stackoverflow.com/questions/61678803
复制相似问题