Page navigation on Indeed website

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
My page navigation has stopped on the Indeed Job search web site. It keeps going from Page 1 to 2 and then back to 1. I can not navigate to page 3 and beyond.

I have been trying to fix it for sometime but can not work out the class or the queryselector. Can someone please take a look and advise were I am going wrong.

This is NO LONGER working
VBA Code:
Do
    If pageNumber >=6 Then Exit Do
        On Error Resume Next
        Set nextPageElement = HTML.getElementsByClassName("np")(0) ' CLICK TO NEXT PAGE

    If nextPageElement Is Nothing Then Exit Do
        Application.Wait (Now + TimeValue("0:00:04"))
        nextPageElement.Click 'next web page
   
   Do While objIE.Busy = True Or objIE.readyState <> 4
    Loop

I have tried the following and several other variations, however nothing seems to work, either it does not go beyond page 1 or loops between page 1+2

VBA Code:
Do
  If pageNumber >=6  Then Exit Do
        'Set nextPageElement = HTML.getElementsByClassName("pagination-list")(0)
       Set nextPageElement = HTML.getElementsByClassName("pagination")(0)
       'Set nextPageElement = HTML.getElementsByClassName("np")(0)
  If Not nextPageElement Is Nothing Then
         nextPageElement.document.querySelector(".np").Click
        'nextPageElement.document.querySelector(".pn").Click
        'nextPageElement.document.querySelector("span.pn").Click
        'nextPageElement.document.querySelector("span.np").Click
        'nextPageElement.document.querySelector(" .pagination-list li:last-child").Click
          Application.Wait (Now + TimeValue("0:00:04"))
        Else:
            Exit Do
        End If

    Do While objIE.Busy = True Or objIE.readyState <> 4
    Loop

For more information Please see this link StackOverflow

I need to select the last "li" and then the a tag or a class in that, however I can not work out how to SELECT the LAST "li" Tag

1621686175262.png
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
When creating a thread in any Excel forum the initial post must be complete but here it's just a partial code,​
a picture of a piece of a webpage code and far above all the URL is missing !​
Anyway as it seems two elements have the same class, as the first element of a class collection is #0​
so to reach the second element of the class 'np' just obviously update the index # to 1 rather than 0 !​
 
Upvote 0
Marc L

Thanks for the update, but I don't fully understand what you are saying as I am limited in VBA is this what you are stating

From
VBA Code:
Set nextPageElement = HTML.getElementsByClassName("pagination")(0)

To
VBA Code:
Set nextPageElement = HTML.getElementsByClassName("pagination")(1)
 
Upvote 0
Mark L

I am still not getting the results if I leave this as is, I get data from page 1+2 and 1 again as it will loop pages 1+ 2
VBA Code:
Do
If pageNumber >=6 Then Exit Do
       Set nextPageElement = HTML.getElementsByClassName("np")(0)
If nextPageElement Is Nothing Then Exit Do
      Application.Wait (Now + TimeValue("0:00:04"))
      nextPageElement.Click 'next web page
Do While objIE.Busy = True Or objIE.readyState <> 4
Loop

If I change this as you said, IF I AM DOING IT RIGHT Then it ONLY extracts 1 page

VBA Code:
Do[B][/B]
If pageNumber >=6 Then Exit Do
       Set nextPageElement = HTML.getElementsByClassName("np")(1)   ' Changed 0 to 1
If nextPageElement Is Nothing Then Exit Do
      Application.Wait (Now + TimeValue("0:00:04"))
      nextPageElement.Click ' CLICK TO NEXT PAGE
Do While objIE.Busy = True Or objIE.readyState <> 4
Loop

I have also tried the following, nothing seems to work. I am not sure what you mean by the #
VBA Code:
    If pageNumber >=6  Then Exit Do
         Set nextPageElement = HTML.getElementsByClassName("pagination")(1)
           'Set nextPage = HTML.querySelector(".pagination-list > li > a > span.pn"
          'Set nextPageElement = HTML.getElementsByClassName("pagination")(0)
    If Not nextPageElement Is Nothing Then
          nextPageElement.document.querySelector(".np").Click
            'nextPageElement.Click 'next web page
            'nextPageElement.document.querySelector(".np")(1).Click
            'nextPageElement.document.querySelector(".np").Click (1)
            'nextPageElement.document.querySelector(" .pagination-list li:last-child").Click
            'nextPageElement.document.querySelector(".pagination a > last").Click
            Application.Wait (Now + TimeValue("0:00:04"))  
       Else:
            Exit Do
        End If
    Do While objIE.Busy = True Or objIE.readyState <> 4
    DoEvents
    Loop

This is the site that I am using Indeed The extraction is fine, the NAVIGATION is the issue as I can not go beyond page 2.

Could you please provide a bit more guidance to your answers. Thanks for so far and for having a look
 
Upvote 0

As I'm very beginner to guess anything so can't help further more without the necessary as yet explained …​
 
Upvote 0
Try to set an Object variable for the class 'np' then in debug mode via a break point check what contains this variable,​
what is the order / position if the expected element is found …​
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top