- Software Degeneracy
- Posts
- How to pull data from a website’s Data API Endpoints
How to pull data from a website’s Data API Endpoints
Sometimes when you’re trying to pull data from a site, scraping with Selenium/BS4 is overkill and you can accomplish your task simply with the Python Requests library.
How to pull data from a website’s Data API Endpoints
Sometimes when you’re trying to pull data from a site, scraping with Selenium/BS4 is overkill and you can accomplish your task simply with the Python Requests library.
The code is VERY Simple:
You basically want to copy the cURL fdrmat from the network tab and format it accordingly with the requests library.
you’re probably wondering how to get that cURL format.
These are the steps to find the data endpoints:
Inspect Element
Go to the Network Tab
Filter by Fetch/XHR Requests
click on requests that look loike they might have the data you want, and go to the responses tab for that code.
Then you just set that cURL up in your code with the url and proper headers, do response = requests.get(url, headers=headers), and print the response.json.
Then from there you can do whatever you want with the data if it’s hittable. Sometimes sites won’t let you hit it directly and that’s when you have to scrape.