Web Scraping & Automation

beautifulsoup4

Untangles messy webpage code into something searchable, like alphabetizing a junk drawer.

Install it: pip install beautifulsoup4

What does it do?

Beautiful Soup takes the raw, often messy HTML code behind a webpage and turns it into a navigable structure, so a program can ask for ‘the third paragraph’ or ‘every link on this page’ instead of scanning through text like reading a phone book cover to cover. Real webpages are frequently broken, mismatched, or sloppily written, and Beautiful Soup is forgiving about that in a way strict tools aren’t. It’s typically paired with Requests, which fetches the page, so Beautiful Soup can focus purely on making sense of what’s inside it. The result is a way to pull exactly the piece of information you want from a page built for humans to look at, not machines to read.

See it in action

This code downloads a webpage and then pulls out its title and every clickable link found on it.

import requests
from bs4 import BeautifulSoup

response = requests.get("https://example.com")
soup = BeautifulSoup(response.text, "html.parser")

print(soup.title.text)
for link in soup.find_all("a"):
    print(link.get("href"))

Why would a non-developer care?

Huge amounts of useful information on the internet — prices, addresses, headlines, reviews — only exist as regular webpages with no clean way to extract them. Beautiful Soup is the tool that turns ‘I can see this data in my browser’ into ‘I can pull this data into a spreadsheet automatically.’ That’s the difference between manually copying a hundred prices by hand and collecting them in seconds.

Real-world examples

Journalists doing data-driven investigations, researchers building datasets from public records sites, and small businesses tracking competitor pricing all commonly reach for Beautiful Soup as a first step. It’s often the very first web scraping tool a newcomer to Python learns, precisely because it’s forgiving of messy real-world pages. Without something like it, extracting structured data from the open web would mean manually copying and pasting, page after page.

Who uses it

Beginners and researchers doing one-off data extraction from websites, rather than large-scale, ongoing crawling operations.

How it compares to alternatives

Beautiful Soup is simpler and more forgiving than lxml, which it can actually use internally as a faster parsing engine, though lxml alone is faster for large jobs. Scrapy is a full crawling framework built for scale, while Beautiful Soup is a focused tool for pulling meaning out of a single page you already have. For sites that load content with JavaScript, none of these alone are enough — that’s where Selenium or Playwright come in.

Fun fact

Beautiful Soup is named after a poem sung by the Mock Turtle in Lewis Carroll’s Alice in Wonderland, chosen because the library was meant to make sense of ‘tag soup’ — badly formed HTML.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries