Skip to content
Advertisement

Selenium – Retrieving html from first page until last page

I’m trying to retrieve the html of the webpage, click the next button, then repeat that action until the last page is reached. I want to get all of the articles’ headlines (h2) by the way, only managed to retrieve some portion of it. Here is my code :

JavaScript

Here is the result

JavaScript

As you can see, it only retrieves a few titles

Thank you!

Advertisement

Answer

Iterate over https://www.cnbcindonesia.com/tag/pasar-modal/$var?kanal=&tipe=

The website you want to scrap is paginated, so you need to iterate over the pages. You cannot just hit the main page (https://www.cnbcindonesia.com/tag/pasar-modal) and get all the data because some of the data is paginated.

Change the $var with page number and set that page as the weblink you want to scrap.

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