0Pricing
Python Academy · Lesson

HTTP Requests with requests and httpx

Fetch web pages, handle redirects, sessions, and headers.

requests Library

requests is the standard synchronous HTTP library. Simple, battle-tested, and perfect for scripts and one-off API calls.

# pip install requests
import requests

r = requests.get("https://api.github.com/users/octocat")
print(r.status_code)   # 200
print(r.json()["login"])   # octocat

Query Parameters and Headers

Pass query parameters with params= and custom headers with headers=.

import requests

r = requests.get(
    "https://api.example.com/search",
    params={"q": "python", "page": 1},
    headers={"Authorization": "Bearer my-token"}
)
print(r.url)    # full URL with query string

All lessons in this course

  1. HTTP Requests with requests and httpx
  2. Parsing HTML with BeautifulSoup
  3. Building a Scrapy Spider
  4. Handling JavaScript and Anti-scraping Measures
← Back to Python Academy