Reputation: 115
Sir I am getting problem to get Data into excel I have some selenium code to get data from URL max pagination number. in to excel.
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
I am getting some error .. i don't know how to make my code working
Upvotes: 0
Views: 622
Reputation: 9568
Not sure but try this
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 Sub
Upvotes: 1