Codzy

Web: HTTP and addresses (URLs)

On the web, the browser sends an HTTP request (method GET to read, POST to send) to a URL, and the server answers with a status code (200 = OK, 404 = not found, 500 = server error) and some content.

A URL has several parts: the scheme (https), the host (codzy.app), the path (/search) and the parameters after the ?. Every web server has to read them: urllib.parse.urlparse splits the URL and parse_qs turns the parameters into a dictionary of lists.

from urllib.parse import urlparse, parse_qs

url = "https://codzy.app/search?q=python&page=2&lang=fr"
parts = urlparse(url)
print("scheme:", parts.scheme)
print("host:", parts.netloc)
print("path:", parts.path)
print("query:", parse_qs(parts.query))

Start the lesson