Tutorial 2 min read

Convert a URL to Markdown in Python and Preserve Source Structure

Converting a URL to Markdown is useful when the returned text preserves the content your application needs.

(Updated: ) • 362 words

Converting a URL to Markdown is useful when the returned text preserves the content your application needs. Keep the source URL and access time with the output, then inspect headings, tables and code before chunking it. A smaller string is not automatically a better source.

Make a fresh conversion request

import os
import requests

url = "https://example.org/permitted-article"
response = requests.post(
    "https://www.searchcans.com/api/v1/url",
    headers={"Authorization": "Bearer " + os.environ["SEARCHCANS_API_KEY"]},
    json={"t": "url", "s": url, "mode": 0, "maxCache": 0, "d": 30000},
    timeout=40,
)
response.raise_for_status()
body = response.json()
if body.get("code") != 0 or not isinstance(body.get("data"), dict):
    raise RuntimeError("Reader did not return a successful data object")
markdown = body["data"].get("markdown")
if not isinstance(markdown, str) or not markdown.strip():
    raise ValueError("No usable Markdown returned")
print(markdown)

The URL above is a placeholder; replace it with a source you are permitted to read. This example does not make an arbitrary example URL into a guaranteed live page. Browser-rendered content has a separate mode and completeness check.

Check structure against the source

Content Check
Main text A required supporting paragraph survives
Headings The sections remain identifiable
Tables Required cells retain their meaning
Code Important code tokens and indentation remain usable
Source identity URL and access time remain attached
Unavailable content An explicit failure replaces a misleading empty success

Do not turn conversion into an accuracy claim

The owned HTML fixture used for this revision retained the required article text, table and code in the candidate Markdown. It is one controlled example, not a whole-web benchmark. If token cost matters, measure both outputs with the tokenizer used by your model and check whether useful evidence was lost.

Use the URL-to-Markdown evaluation guide when choosing a provider, and the ingestion contract when deciding whether an extracted document is safe to index. This page completes the conversion and inspection task; it does not rank every extraction vendor.

Reference documentation: www.searchcans.com — /reader-api.

Tags:

Tutorial AI Markdown RAG LLM API Development
SearchCans Team

SearchCans Team

SERP API & Reader API Experts

The SearchCans engineering team builds high-performance search APIs serving developers worldwide. We share practical tutorials, best practices, and insights on SERP data, web scraping, RAG pipelines, and AI integration.

Ready to build with SearchCans?

Test SERP API and Reader API with 100 free credits. No credit card required.