How to scrape the next page when selector repeated in pagination?

I use a._1f-eo:last selector for the pagination.

I don’t know in advance how many pages there will be so I want to click on the next page button to go to the next until it is disabled. I assume this is the way agenty works

The problem is that the next page button has the same class as the previous, or numbered page buttons. So I use the :last CSS selector. but it doesn’t works.

You should be using the :nth-last-child(n) selector to paginate in this case.

Because if you see the HTML > The Next button is the last item (li) of this list (ul) and will always be in last, so we can use the :nth-last-child(1) easily.

This is just opposite of nth-child(n) selector, and will count the number from the last child traversing towards backward.

So the correct selector to paginate will be ._25feg :nth-last-child(1) a

Learn more about this selector here - https://www.w3schools.com/cssref/sel_nth-last-child.asp

And pagination docs here - https://www.agenty.com/docs/scraping-agent/pagination-in-web-scraping