DEV Community

bao001 xiao
bao001 xiao

Posted on

How to Extract Clean Content From Any URL in 3 Lines of Python

Have you ever needed to grab the actual content from a web page — without all the ads, nav bars, and JavaScript junk?

Whether you're building an AI training pipeline, a reading app, or a data scraper, extracting clean text from arbitrary URLs is a universal pain point.

Here's the fastest way I've found.

The Problem

Most websites are 70% boilerplate. Headers, footers, sidebars, cookie banners, popups. If you just use requests.get() and parse the HTML, you get garbage:

import requests
from bs4 import BeautifulSoup

resp = requests.get("https://example.com/article")
soup = BeautifulSoup(resp.text, "html.parser")
print(soup.get_text())
# Output: navigation menu sidebar footer ads copyright...
Enter fullscreen mode Exit fullscreen mode

The Solution: One API Call

Instead of fighting with HTML parsing, use a dedicated content extraction API:

import requests

resp = requests.post("https://web2md-api-production-d822.up.railway.app/extract", json={
    "url": "https://www.python.org/doc/",
    "format": "markdown"
})
data = resp.json()
print(data["content"][:500])
Enter fullscreen mode Exit fullscreen mode

That's it. Three lines. The API handles:

  • Fetching the page
  • Stripping all boilerplate (nav, ads, scripts)
  • Extracting the main article content
  • Converting to clean Markdown

What You Get Back

The API returns structured JSON:

{
  "success": true,
  "title": "Documentation — Python.org",
  "content": "# Markdown content here...",
  "description": "The official home of the Python Programming Language",
  "word_count": 1234,
  "response_time_ms": 850
}
Enter fullscreen mode Exit fullscreen mode

Format Options

  • markdown (default) — perfect for LLM training data, note-taking, publishing
  • json — structured paragraphs, headings, and metadata
  • text — plain text when you just need the words

Pricing

It's cheap. Free tier handles 50 requests/day — enough for most side projects.

  • Free: 50 requests/day
  • Basic: 5,000/month — $4.99
  • Pro: 50,000/month — $19.99

Real Use Cases

  1. AI Training Data — Feed clean web content into your LLM fine-tuning pipeline
  2. Research — Download articles for offline reading and analysis
  3. Content Monitoring — Track changes on competitor pages
  4. Reading Apps — Convert any article to a clean reading view

Why Not Just Use BeautifulSoup?

You can, but:

  • Every site has different HTML structure
  • JavaScript-rendered content won't appear
  • You'll spend hours writing selectors for each site
  • Maintenance nightmare when sites redesign

A dedicated extraction API handles all of this with one endpoint. No selectors, no maintenance, no hassle.


This article was written with the help of AI. The API mentioned is a personal project — I built it because I needed it myself.

Top comments (0)