Skip to content
Advertisement

How to scrape data from html table with python?

I am trying to scrape data from the html tables on this page and export it to a csv.

The only success i’ve had is with extracting the headers. I thought the problem might be with the page not fully loading before the data is scraped, hence my use of the the ‘requests_html’ library, but the issue still persists.

Here’s the code i am using:

JavaScript

Any help would be grateful, thanks

Advertisement

Answer

Your assumption is correct, the contents are only reloaded when the corresponding areas are opened, so you should also start at this point and retrieve the data via these separate requests.

Simply change the value of id parameter for https://www.fidelitypensionmanagers.com/Services/GetPriceHistory?id=1&format=json

You can get the ids from the onclick:

JavaScript

Example

simplest approach would be to use pandas in my opinion:

JavaScript

Output

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