Your First Python Web Scraper: Zero Setup, Just Click and Run
Want to learn web scraping but don't want to mess with installing Python, libraries, and dependencies? You're in the right place.
Today, you'll build your first web scraper using Google Colab - no installation required. Just click a link and start scraping.
What You'll Build
We'll scrape a simple online bookstore and extract:
Book titles
Prices
Ratings
Categories
Stock information
By the end, you'll have working code that turns messy HTML into clean, usable data.
Before We Start
What you need:
A Google account (that's it!)
10 minutes
What you DON'T need:
Python installed
Command line knowledge
Any setup whatsoever
Step 1: Open Google Colab
๐ Click here to open the tutorial in Google Colab (you'll create this link after making the notebook)
Or manually:
File โ New Notebook
Step 2: Install Libraries
Copy this into the first cell and run it (Shift+Enter):
# Install required libraries (takes 10 seconds)
!pip install beautifulsoup4 requests
print("โ
Libraries installed!")
That's it. Setup done. Now let's scrape.
Step 3: Your First Scrape
I've created a simple bookstore page for us to practice on. It's hosted on GitHub Pages, so it's always available.
See the page here: https://umanggulati.github.io/python-demo/products.html
Now let's scrape it. Copy this into a new cell:
import requests
from bs4 import BeautifulSoup
# Fetch the page
url = 'https://umanggulati.github.io/python-demo/products.html'
response = requests.get(url)
# Parse the HTML
soup = BeautifulSoup(response.content, 'html.parser')
print("โ
Page loaded successfully!")
print(f"๐ Page title: {soup.title.string}")
Run it. If you see "Page loaded successfully!", you just scraped your first webpage!
Step 4: Extract Book Titles
Let's get all the book titles:
# Find all product titles
titles = soup.find_all('h2', class_='product-title')
print(f"๐ Found {len(titles)} books:\n")
for title in titles:
print(f" โข {title.text}")
Output:
๐ Found 5 books:
โข Python Crash Course, 3rd Edition
โข Fluent Python, 2nd Edition
โข Automate the Boring Stuff with Python
โข Python for Data Analysis, 3rd Edition
โข Flask Web Development, 3rd Edition
See how easy that was? .find_all() grabs every matching element. .text extracts the text.
Step 5: Extract Prices
# Find all prices
prices = soup.find_all('div', class_='price')
print("๐ฐ Book prices:\n")
for price in prices:
print(f" {price.text}")
Output:
๐ฐ Book prices:
$39.99
$54.99
$34.99
$49.99
$44.99
Step 6: Clean the Prices
Those strings aren't useful for math. Let's convert them to numbers:
# Extract and clean prices
prices = soup.find_all('div', class_='price')
print("๐ฐ Book prices (cleaned):\n")
for price in prices:
# Remove $ and convert to float
clean_price = float(price.text.strip('$'))
print(f" ${clean_price:.2f}")
# Calculate average
price_values = [float(p.text.strip('$')) for p in prices]
average = sum(price_values) / len(price_values)
print(f"\n๐ Average price: ${average:.2f}")
Output:
๐ฐ Book prices (cleaned):
$39.99
$54.99
$34.99
$49.99
$44.99
๐ Average price: $44.99
Now you can do math with your scraped data!
Step 7: Extract Multiple Things at Once
Let's get title AND price together:
# Find all product cards
products = soup.find_all('div', class_='product-card')
print(f"๐ฆ Found {len(products)} products:\n")
for product in products:
# Extract data from each product
title = product.find('h2', class_='product-title').text
price = product.find('div', class_='price').text
print(f" {title}")
print(f" โโ {price}\n")
Output:
๐ฆ Found 5 products:
Python Crash Course, 3rd Edition
โโ $39.99
Fluent Python, 2nd Edition
โโ $54.99
Automate the Boring Stuff with Python
โโ $34.99
[...]
Step 8: Extract Categories
Each book has category tags. Let's get those:
products = soup.find_all('div', class_='product-card')
print("๐ท๏ธ Books by category:\n")
for product in products:
title = product.find('h2', class_='product-title').text
categories = product.find_all('span', class_='category')
# Extract text from each category
category_list = [cat.text for cat in categories]
print(f" {title}")
print(f" โโ {', '.join(category_list)}\n")
Output:
๐ท๏ธ Books by category:
Python Crash Course, 3rd Edition
โโ Beginner, Projects
Fluent Python, 2nd Edition
โโ Advanced, Best Practices
Automate the Boring Stuff with Python
โโ Beginner, Automation
[...]
Step 9: Find Low Stock Items
Let's find books that are running low:
products = soup.find_all('div', class_='product-card')
print("โ ๏ธ Low stock alert:\n")
for product in products:
stock_element = product.find('p', class_='stock')
# Check if it has the 'low' class
if stock_element and 'low' in stock_element.get('class', []):
title = product.find('h2', class_='product-title').text
stock_text = stock_element.text
print(f" ๐จ {title}")
print(f" {stock_text}\n")
Output:
โ ๏ธ Low stock alert:
๐จ Automate the Boring Stuff with Python
In Stock: 3 units
Step 10: The Complete Scraper
Let's put it all together and save the data:
import requests
from bs4 import BeautifulSoup
import json
# Fetch and parse
url = 'https://umanggulati.github.io/python-demo/products.html'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
# Find all products
products = soup.find_all('div', class_='product-card')
print(f"๐ฆ Scraping {len(products)} products...\n")
# Extract all data
products_data = []
for product in products:
product_dict = {
'id': product.get('data-product-id'),
'title': product.find('h2', class_='product-title').text,
'price': float(product.find('div', class_='price').text.strip('$')),
'rating': product.find('div', class_='rating').text,
'categories': [cat.text for cat in product.find_all('span', class_='category')],
'stock': product.find('p', class_='stock').text,
'description': product.find('p', class_='description').text.strip()
}
products_data.append(product_dict)
# Display as formatted JSON
print(json.dumps(products_data, indent=2))
print(f"\nโ
Successfully scraped {len(products_data)} products!")
This outputs clean, structured data you can use anywhere!
Step 11: Save to CSV (Bonus)
Want to open this in Excel or Google Sheets?
import csv
# Save to CSV
with open('products.csv', 'w', newline='', encoding='utf-8') as f:
writer = csv.DictWriter(f, fieldnames=['id', 'title', 'price', 'rating', 'categories', 'stock'])
writer.writeheader()
for product in products_data:
# Convert categories list to string for CSV
product_copy = product.copy()
product_copy['categories'] = ', '.join(product['categories'])
writer.writerow({k: product_copy[k] for k in ['id', 'title', 'price', 'rating', 'categories', 'stock']})
print("โ
Saved to products.csv")
# Download the file (in Colab)
from google.colab import files
files.download('products.csv')
The CSV downloads automatically! Open it in Excel or Sheets.
What You Just Learned
In 10 minutes, you learned to:
Load and parse HTML
Find elements by class name
Extract text content
Navigate nested HTML
Clean and process data
Save to JSON and CSV
These skills work on any website. The same code. Just different class names.
Try It Now!
Don't just read. Run the code in Colab. Change things. Break it. Fix it. That's how you learn.
Open Google Colab and start scraping: colab.research.google.com
Quick Tips for Colab
Run a cell: Shift + Enter
Add new cell: Click "+ Code" or "+ Text"
Save your work: File โ Save (auto-saves to Google Drive)
Download notebook: File โ Download โ Download .ipynb
Resources:
Happy scraping! ๐