5 Easy Steps to Build Your First Web Scraper (Python)

Build a real working web scraper in 5 minutes. Learn how to inspect HTML, send requests, and extract data using Python, Requests, and BeautifulSoup.

5 Easy Steps to Build Your First Web Scraper (Python)
On this page
  1. Introduction
  2. Prerequisites
  3. Step 1: Inspect the Target Page
  4. Step 2: Send HTTP Request
  5. Step 3: Parse the HTML
  6. Step 4: Extract the Data
  7. Step 5: Save to CSV
  8. Visual Guide: How Scrapers Work
  9. FAQ

Introduction

Data is the new oil, but it's often locked behind websites. Web scraping is the key to unlocking it.

In this guide, we'll build a real web scraper in Python in just 5 easy steps. We'll extract quotes from a practice website, understand how it works, and save the data to a CSV file. No complex frameworks—just pure Python power.

Prerequisites

Setup

You need Python installed. Then, install two essential libraries:

  • requests: To download the web page.
  • beautifulsoup4: To read the HTML and find data.
pip install requests beautifulsoup4

Step 1: Inspect the Target Page

Before coding, we need to know what we're looking for. Open http://quotes.toscrape.com in your browser.

Right-click on a quote and select Inspect. You'll see the HTML structure looks like this:

<div class="quote">
    <span class="text">"The world as we have created it is a process of our thinking."</span>
    <small class="author">Albert Einstein</small>
</div>

Goal: We want to grab the text inside span.text and the author inside small.author.

Step 2: Send HTTP Request

We need to download the HTML code of the page into our Python script. We use the requests library for this.

import requests

url = "http://quotes.toscrape.com"
response = requests.get(url)

print(response.status_code) 
# Output: 200 (Which means "OK")

Step 3: Parse the HTML

We have the raw HTML text, but it's just a giant string. BeautifulSoup converts this string into a tree of objects that we can navigate (like "find all divs").

from bs4 import BeautifulSoup

soup = BeautifulSoup(response.text, "html.parser")

# Now 'soup' is a searchable object!
print(soup.title.text) 
# Output: Quotes to Scrape

Step 4: Extract the Data

Now the magic happens. We loop through all elements with the class quote and pluck out the text and author.

quotes_data = []

# Find all quote cards
quote_elements = soup.find_all("div", class_="quote")

for quote in quote_elements:
    text = quote.find("span", class_="text").text
    author = quote.find("small", class_="author").text
    
    quotes_data.append({
        "text": text,
        "author": author
    })

print(f"Scraped {len(quotes_data)} quotes!")

Step 5: Save to CSV

Data is useless if you don't save it. Let's write our list of dictionaries to a CSV file using Python's built-in csv module.

Complete Code

import requests
from bs4 import BeautifulSoup
import csv

url = "http://quotes.toscrape.com"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")

quotes_data = []
quote_elements = soup.find_all("div", class_="quote")

for quote in quote_elements:
    text = quote.find("span", class_="text").text
    author = quote.find("small", class_="author").text
    quotes_data.append({"text": text, "author": author})

# Saving to CSV
with open("quotes.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=["text", "author"])
    writer.writeheader()
    writer.writerows(quotes_data)

print("Done! Check quotes.csv")

Visual Guide: How Scrapers Work

How Web Scraping Works Diagram

The Scraping Lifecycle

  1. Request: Python sends an HTTP GET request (like a browser).
  2. Response: Server sends back raw HTML strings.
  3. Parse: BeautifulSoup converts strings into a DOM Tree.
  4. Extract: We select specific nodes (tags) from that tree.
  5. Store: Extracted strings are saved to a file.

Frequently asked questions

Is web scraping legal?

generally yes for public data, but you must respect the website's terms of service and robots.txt file. Don't scrape personal data or copyrighted content.

What if the website uses JavaScript (React/Vue)?

Requests + BeautifulSoup won't work because the HTML is empty until JS runs. You'll need a tool like Playwright, Selenium, or Firecrawl (see our other guide!).

How do I scrape multiple pages?

Wrap your code in a loop! Find the 'Next' button link, update the URL, and repeat the request process.

Keep reading

What is Data Scraping? Prevention, Mitigation & Ethical RulesWeb Scraping

What is Data Scraping? Prevention, Mitigation & Ethical Rules

Everything you need to know about web scraping: how it works, legitimate vs malicious uses, legal considerations, ethical rules, and how to protect your website.

MD Kawsar· January 18, 2026 · 11 min read
BeautifulSoup Complete Guide: Parse, Navigate, ExtractWeb Scraping

BeautifulSoup Complete Guide: Parse, Navigate, Extract

The definitive guide to BeautifulSoup. Master HTML parsing, tree navigation, find_all(), CSS selectors, and data extraction with practical examples.

MD Kawsar· January 18, 2026 · 10 min read
Firecrawl Guide: Turn Websites into LLM-Ready DataWeb Scraping

Firecrawl Guide: Turn Websites into LLM-Ready Data

Discover Firecrawl, the developer-first tool that converts any website into clean Markdown for AI agents and RAG pipelines.

MD Kawsar· January 18, 2026 · 6 min read

Want us to build this for you?

Tell us what data or workflow you need. We reply within a few hours.

Book a free call ↗