0

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.

here is 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

I am getting some error .. i don't know how to make my code working

enter image description here

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @YasserKhalil Sir. its perfect as I want. thanks a lot
Sir Can you Help me more.. if I have multiple url list ... how I can loop this code to all urls .
It is better to post a new question and I will have a look and see if I can help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.