How to scrape a website HTML using requests

1 min

The requests library is probably one of the simplest library to use when you want to execute an HTTP call from Python script.

Asking for raw HTML

Some website will give you raw HTML only, because they are not supposed to give you a JSON back. It is the example with

import requests # To make HTTP calls

url = ""
response = requests.get(url)
getting facebook front-page data

And if you print the response.text it will print out the html content that your call retrieved.

getting facebook front-page data
<!DOCTYPE html>
<html lang="de" id="facebook" class="no_js">
<head><meta charset="utf-8" /><meta name="referrer"
the first lines of the html response

In order to properly work with your data you will need now to parse the HTML.

You can do that using Beautiful Soup library in Python