To turn a URL into Markdown with an API, call GET /web/extract with format=markdown. The web scraping API returns the page as text/markdown and keeps headings, lists, tables, and code. For a list of URLs, the tool in this guide calls GET /web/extract with format=markdown for each one and writes one .md file per page that has text.
page2md.py reads URLs from the command line or from a text file. For each one it calls GET /web/extract with format=markdown and js=false, and saves the Markdown as returned with a short front matter block. With --format html or --format text it converts the response locally instead. If a page comes back with no readable text, it tries once more, then marks that URL empty and writes no file.
The worked example is Turn Web Pages into Markdown with Python. The source is the page-to-markdown-api folder in the Desearch Python examples repo.
The basics
- Base URL:
https://api.desearch.ai - Auth:
Authorization: $DESEARCH_API_KEY(the raw key from Desearch Console) - Endpoint:
GET /web/extract - Parameters:
url(required),format(text,markdown, orhtml, defaulttext),js(trueorfalse, defaultfalse),full_page(trueorfalse, only withformat=text) - SDK:
desearch-py1.2.1 exposesweb_crawl(url, format="text"), which callsGET /web/crawlwithurlandformat. The 1.2.1 package has noextractmethod andweb_crawlhas nojsparameter. The example callsGET /web/extractfrom the standard library.
The example CLI uses the standard library. requirements.txt lists pytest only. The snippets below are taken from that folder.
Get a key
Create a key in Desearch Console. The example reads DESEARCH_API_KEY, or a file path from DESEARCH_API_KEY_FILE:
Point the file form at a path outside the project:
The key is sent on the request. It is not written into the Markdown files.
Get Markdown in one call
If you only need the Markdown, ask for it directly:
The body is the Markdown itself, sent as text/markdown. For articles and docs it holds the main content. For other pages it holds the whole page without its navigation. This is what the tool below requests by default.
The request the tool sends
The tool sends the same call with js=false and its own User-Agent:
format defaults to text on the API, so the tool always sends it: markdown unless you pass --format html or --format text. js must be the string true or false. The tool sends false.
The example builds that request with the standard library. BASE is https://api.desearch.ai, and UA starts with page-to-markdown/0.1:
| Parameter | Required | What it sends |
|---|---|---|
url | yes | The page to read. |
format | no | text, markdown, or html. Default text. The example sends markdown unless you pass --format. |
js | no | true or false. Default false. The example sends false. |
wait | no | Extra wait in milliseconds, from 0 to 30000. Applied only when js=true. The example omits it. |
With js=false, Extract reads the HTML the server sends. The parameter list for the endpoint is in the Extract API reference. The product page is Web scraping API, and the Extract API guide is in the docs.
Use the HTTP call above for js=false on GET /web/extract. In desearch-py 1.2.1, web_crawl accepts url and format only.
What the tool writes
The flags match the example on main (commit a95e1d6f):
urls.txt has one URL per line. Lines that start with # are skipped. --out defaults to out. --format defaults to markdown, which is saved as returned. html and text are converted locally.
For each URL the tool calls page_to_markdown(). That function exists in page2md.py:
A blank or malformed URL is skipped locally, before any call. A 200 response with no readable text is tried once more. The tool then marks that URL empty and writes no file. A page that returns an error, or that cannot be reached, comes back as a non-200 status with a short detail message.
--out receives:
pages/: one Markdown file per page that has text, with front matter for the source URL, title, time, status, attempts, and word countsummary.md: one row per URL, including status, attempts, words, and latency
What a run returned
On 2026-10-15 at 15:35 (Asia/Tbilisi) the tool ran python page2md.py urls.txt --out out/ over 10 URLs: 3 static pages, 3 docs pages, 2 news pages, 1 page that builds its content with JavaScript, and 1 URL that does not exist. That run used the October 2026 version of the tool, which requested format=html and converted it locally. The current version requests format=markdown by default.
7 of 10 URLs became Markdown files. The console lines for that run show 24 words on the shortest page and 4,031 words on the longest. The seven pages that became files took 1.07 to 4.83 seconds each, with a median of 1.94 seconds.
The page that builds its text in the browser came back empty. With js=false, Extract reads the HTML the server sends, and the tool flags pages that come back empty, so that URL was flagged and no file was written. Two URLs returned status 404, and no file was written for them.
The saved Markdown for the Python tutorial starts like this:
What to expect
- With
js=false, Extract reads the HTML the server sends. Articles, docs, and reference pages convert well. Pages that build their text in the browser come back with little or no text. The tool writes no file for those pages. - A page that does not exist, or that cannot be reached, returns a non-200 status with a short
detailmessage. Checksummary.mdfor those rows. - Failed extract requests are not charged. A page with no text returns
404witherror_codeno_content. A page that only shows its content after JavaScript runs returns422witherror_codejs_required: retry that URL withjs=true, which is billed on a separate tier. - Validate URLs before you send them. The tool skips blank or malformed URLs locally.
- Send your own
User-Agentheader. The example's starts withpage-to-markdown/0.1.
What it costs
Extract is listed at $0.50 per 1,000 pages on the pricing page (reference rate as of 7 May 2026). That is $0.0005 per page. Console shows the rate on your account.
On 2026-10-15, each of the seven pages that became a Markdown file was $0.0005, the same as that rate.
Run the example
The example folder includes page2md.py, core.py, offline tests, a sample URL list, sample output, and a README.
Set DESEARCH_API_KEY_FILE or DESEARCH_API_KEY, then run:
The offline tests do not call the API. Run them with pytest -q.
You can also import page_to_markdown and pass a client that does not write to disk:
Ideas to extend it
- Run it on a sitemap to build a Markdown copy of your own docs for search or Q&A.
- Diff today's Markdown against yesterday's to see what changed on a page.
- Wrap
page_to_markdown()in a small web service that takes?url=and returns Markdown.
Frequently asked questions
How do I turn one URL into Markdown?
Call GET /web/extract with url and format=markdown. The response is the page as Markdown, and the example saves it as returned. To control the conversion yourself, run the example with --format html and it converts the HTML locally.
What if the page comes back empty?
With js=false, Extract reads the HTML the server sends. The tool flags a page with no readable text. It tries once more, then writes no file. If the page needs JavaScript to show its text, the API answers 422 with error_code js_required, and you can retry with js=true.
How do I keep a bad URL from becoming a call?
The tool skips a blank or malformed URL locally. The check requires an http or https scheme and a host.
Where is the full example?
The CLI, the local converter for --format html, the offline tests, and a sample run are in page-to-markdown-api. A walkthrough of the same tool is on Turn Web Pages into Markdown with Python.
Related examples: Article summarizer with MCP.
