Web scraping sounds mysterious until you break it into four steps: fetch a page, parse the HTML, extract the fields you care about, and store the result. This guide walks through that path with Python, then covers the ethics and legality basics you should know before you scale.
If you want the short conceptual version first, read What is Web Scraping?.
What you are actually doing
A website is HTML (and CSS/JS) meant for browsers. A scraper is a program that:
- Requests a URL the way a browser would (over HTTP)
- Reads the response body
- Finds elements — titles, prices, links — with selectors
- Writes structured data (CSV, JSON, a database)
You are not “hacking.” You are automating reading of pages that are already public. That still comes with rules: rate limits, robots.txt, privacy law, and site terms. More on that below.
The minimal stack
For most beginner projects, start with:
- Python
- requests — download the page
- Beautiful Soup — parse HTML (cheatsheet)
Install:
pip install requests beautifulsoup4 lxml
Your first scraper
This example pulls the page title and all links from example.com. Swap the URL for a public page you are allowed to practice on.
import requests
from bs4 import BeautifulSoup
url = "https://example.com"
headers = {
"User-Agent": "LearningBot/1.0 (+https://plainenglish.io; beginner tutorial)"
}
response = requests.get(url, headers=headers, timeout=30)
response.raise_for_status()
soup = BeautifulSoup(response.text, "lxml")
title = soup.title.get_text(strip=True) if soup.title else None
links = [
{"text": a.get_text(strip=True), "href": a.get("href")}
for a in soup.find_all("a", href=True)
]
print({"title": title, "link_count": len(links), "links": links[:5]})
That pattern — GET → BeautifulSoup → select → print/save — is the core of most static-site scrapers.
Choosing selectors
Prefer stable CSS selectors over brittle absolute paths:
article h2— headings inside articles.price— a class the site already usesa.product— links with a product class
Inspect the page in your browser’s DevTools, copy a selector, and test it in a small script before you crawl hundreds of URLs.
Save something useful
Printing is fine for learning. For real work, write JSON or CSV:
import json
with open("links.json", "w", encoding="utf-8") as f:
json.dump(links, f, ensure_ascii=False, indent=2)
When plain requests is not enough
If response.text is missing the content you see in Chrome, the site is probably rendering with JavaScript. You need a headless browser such as Playwright. See Scrape JavaScript-Heavy Sites with Playwright and the Playwright cheatsheet.
Not sure which tool to pick? Read Choose Your Web Scraping Stack.
Be a good citizen
Before you scale past a handful of pages:
- Check
robots.txt— see What is robots.txt? - Throttle — add delays; do not hammer a small site
- Identify yourself — use a clear User-Agent with contact info
- Prefer APIs — if the site offers one, use it
- Stay on public data — logged-out pages are a different risk profile than authenticated scrapes
Legal snapshot (not legal advice)
In the US, courts have generally treated scraping publicly available pages differently from bypassing access controls. Contracts, privacy law (GDPR/CCPA), and misuse of data still matter. For a deeper walkthrough, read Is Web Scraping Legal?.
What to learn next
- Practice on a simple static site until selectors feel natural
- Learn Beautiful Soup thoroughly via the cheatsheet
- Move to Playwright when you hit JS-rendered pages
- Only then think about proxies, anti-bot systems, and large crawls
Scraping is a skill of careful extraction, not of maximum aggression. Start small, stay polite, and grow the pipeline when the data — and the site — can handle it.
Comments
Loading comments…