Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Scraping data from a container

I’m new to scraping and would like to scrape this the "Historical Data" table from this url: https://coinmarketcap.com/currencies/bitcoin/historical-data/

I have tried to use bs4 but nothing seems to work for me as it just returns an empty list…
As far as I understand, what I need to do is to find all "tr" in the container – or what?
I don’t have that much code, but I think it make sense to show it to you so there is something to work with:

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

page = requests.get("https://coinmarketcap.com/currencies/bitcoin/historical-data/")
soup = BeautifulSoup(page.content, 'html.parser')
soup.find_all('tr')

>Solution :

The data you are looking for is added to the page via XHR/Fetch call. You can get it like the below

import requests

r = requests.get('https://api.coinmarketcap.com/data-api/v3/cryptocurrency/historical?id=1&convertId=2781&timeStart=1633910400&timeEnd=1639180800')
if r.status_code == 200:
  print(r.json())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading