Skip to content
Advertisement

Looping through pages of search result

I am trying to scrape Reuters image captions on certain pictures. I have searched with my parameters and have a search result with 182 pages. The ‘PN=X’ part at the end of the links are the page numbers. I have built a for loop to loop through the pages and scrape all captions:

JavaScript

The code runs, but it returns the same captions regardless of the page it is given. It just repeats the same 47 results over and over again. But when I enter the pages into my browser, they are different from each other. So it should give different results. Any idea how to fix?

Advertisement

Answer

For this website, to get different results for each page is more complicated than just adding a page number to the URL and using requests.get().

A simpler approach in this case would be to use selenium, for example:

JavaScript

Obviously, a different browser can be used.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement