Wikipedia Scraper: Articles, Tables & Infoboxes

Live-tested Wikipedia scraper guide: article markdown with JSON-LD, infobox and table recipes the cleaner drops, keyless REST APIs, and the crawl trap.

MMotherlode Lab10 min read
Magpie title card: Wikipedia Scraper: Articles, Tables & Infoboxes

Wikipedia is the politest big target on the web: no login, no WAF, no CAPTCHA, and a robots.txt that openly welcomes polite crawlers. Yet most “wikipedia scraper” tutorials still teach BeautifulSoup selectors and stop short of the parts people actually want: the infobox and the data tables, which article-style cleaners throw away wholesale. I ran a wikipedia scraper against every door the site offers on 2026-10-30 from a home connection: articles with full bibliographies, infobox and table recipes, three keyless APIs, and the crawl setting that turns a failing crawl into a clean one.

All commands below ran with Magpie, a local CLI scraper (free, AGPL-3.0-or-later/commercial dual license). Static fetch handled everything; Wikipedia never once asked for a browser.

One license note first, because it changes what you build: Wikipedia text is CC BY-SA 4.0 (plus GFDL). Scraping is fine; republishing requires attribution and share-alike. This is general information, not legal advice.

The rules, in Wikipedia’s own words

The User-agent: * block of en.wikipedia.org/robots.txt is unusually readable. It allows four specific paths (/w/api.php?action=mobileview&, /w/load.php?, /api/rest_v1/?doc, and the sitemap endpoint), then disallows the rest of the machinery:

Path What it is
/w/ MediaWiki internals: index.php, load.php, edit actions
/api/ The REST and Action API endpoints
/trap/ A honeypot for crawlers that ignore robots.txt
/wiki/Special: (plus localized spellings) Special pages
Dozens of Wikipedia: namespace paths Meta pages, deletion discussions, sandboxes

Three details worth your attention. Crawl-delay: 5 exists in the file, but it applies to SemrushBot only, not to the * group. The declared Sitemap: https://en.wikipedia.org/w/rest.php/site/v1/sitemap/0 returned 403 every way I tried it: bare curl, curl with a Chrome User-Agent, and Magpie’s TLS stack. The sitemap is declared and dead at the same time, which kills magpie map:

$ magpie map "https://en.wikipedia.org/wiki/Web_scraping"
Error: crawl: map: GET https://en.wikipedia.org/w/rest.php/site/v1/sitemap/0: HTTP 403

And /trap/ is not decoration. Wikimedia blocks crawlers that misbehave, and the robots preamble says so in plain English (“some misbehaved spiders out there”). Respect the Disallow lines and this file never becomes your problem. For the full mechanics of robots.txt and crawl-delay, see our robots.txt guide.

One Magpie-specific nuance: magpie scrape is a user-directed fetch and does not consult robots.txt; magpie crawl does, and it refuses robots-disallowed seeds. That distinction becomes the plot of the crawl section below.

Six doors, one bricked shut

Everything Wikipedia publishes about a topic is reachable through six doors. Five open.

Door URL shape Status What you get
Article page /wiki/{Title} Static 200 Full prose, headings, citations, Article JSON-LD
Summary API /api/rest_v1/page/summary/{Title} Keyless JSON Description, extract, thumbnail, Wikidata ID
Media list /api/rest_v1/page/media-list/{Title} Keyless JSON Every image with captions
Action API /w/api.php?action=query&prop=extracts Keyless JSON Plaintext article text, no HTML
Wikitext source /w/index.php?title={Title}&action=raw Static 200 Raw wikitext, infobox in pipe syntax
Declared sitemap /w/rest.php/site/v1/sitemap/0 403 A Wikimedia Error page

The robots disallows on /w/ and /api/ apply to crawlers walking the site, not to you calling an API. If you point magpie scrape at an API URL it fetches fine (user-directed, no robots consult); magpie crawl would refuse it as a seed. Call the APIs from your own code and set a descriptive User-Agent while you’re at it; Wikimedia’s API etiquette asks for exactly that.

Running the Wikipedia scraper with Magpie

The article page is the bread and butter, and cleaning works unusually well here because Wikipedia’s boilerplate is structural, not JS-injected. One command:

$ magpie scrape "https://en.wikipedia.org/wiki/Web_scraping" --out page.json

The result for that page: 31,789 characters, 3,376 words, 18 section headings. The markdown keeps the lead definition intact, converts every cross-reference to an absolute en.wikipedia.org/wiki/{Title} link, and preserves the citation markers ([\[4\]](#cite_note-4)) as working anchors into the bibliography. The References section survives in full, numbered, with authors, DOIs, and retrieval dates, which is why Wikipedia is such a good corpus source for citation-following: you scrape one page and get its entire evidence trail. The same cannot be said of every reference-heavy site; arXiv needs a different treatment entirely.

The JSON-LD sidecar carries one Article block, abridged below, and it’s richer than most sites bother to ship:

{
  "@type": "Article",
  "name": "Web scraping",
  "sameAs": "http://www.wikidata.org/entity/Q665452",
  "author": {"@type": "Organization", "name": "Contributors to Wikimedia projects"},
  "publisher": {"@type": "Organization", "name": "Wikimedia Foundation, Inc."},
  "datePublished": "2005-09-17T18:57:30Z",
  "dateModified": "2026-09-19T09:13:04Z"
}

datePublished is the page’s creation date, 2005, and dateModified is the last edit. The sameAs field hands you the Wikidata Q-ID (Q665452), which is the cleanest join key you will ever get for cross-language and cross-dataset linking. If you want this as a typed record instead of raw JSON-LD, --vertical article turns the block into a structured object with the same fields.

Two blemishes, both cosmetic. The maintenance banners (“more citations needed”) are dropped, which is what you want. The per-section edit links are kept (anchor text [edit], href ending in action=edit&section=N), one pair per section; a one-line regex strips them if they bother your pipeline.

Infoboxes don’t survive cleaning (and the two fixes)

The infobox, that summary box on the right of nearly every article, is technically an HTML table, and the cleaner treats it as boilerplate. I proved the loss on the Python page: the clean markdown came back at 3,043 words, and the word “Paradigm” (the infobox’s first field) appears nowhere in it. The only table that survived is the left-sidebar navigation, five pipe rows of “part of a series on” links.

Fix one keeps the rendered box:

$ magpie scrape "https://en.wikipedia.org/wiki/Python_(programming_language)" \
    --include ".infobox" --page-format html --out infobox.html

That returns 33,849 bytes of infobox-only HTML, 23 table rows, fields intact: Paradigm, Designed by Guido van Rossum, First appeared 20 February 1991, Stable release 3.15.2 (26 October 2026, current as of my test), License, Filename extensions. Feed the file to pd.read_html("infobox.html", encoding="utf-8") and you get a 22×2 DataFrame, fields clean.

Fix two skips the HTML entirely and takes the wikitext source:

$ magpie scrape "https://en.wikipedia.org/w/index.php?title=Mount_Fuji&action=raw" \
    --page-format raw
{{Infobox mountain
| name = Mount Fuji
| image = View of Mount Fuji from Ōwakudani 20211202.jpg

Wikitext pipe syntax is the stable, machine-readable representation of infobox fields, and it has not changed format in a decade. Use fix one when you want rendered values (formatted dates, linked names), fix two when you’re parsing fields en masse across thousands of articles.

Tables: keep the HTML, parse locally

Data tables are where article cleaners die, and Wikipedia’s tables are among the best data on the web. The proof page is List of countries by GDP (nominal): 238 table rows carrying IMF, World Bank, and UN figures. Cleaned as an article, that page returns 651 words and zero table rows. The entire dataset is gone; only the surrounding prose survives.

Scoping the cleaner to the table and staying in markdown doesn’t rescue it, either. With --include "table.wikitable" and default output, the cells come back flattened into mush (World128,003,776118,350,166111,565,144), which is worse than nothing because it looks parseable.

The working recipe is the same shape as the infobox fix: scope to the table, keep HTML.

$ magpie scrape "https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)" \
    --include "table.wikitable" --page-format html --out gdp.html

400,906 bytes, 2 <table> elements, 238 <tr> rows, with the IMF 2026, World Bank 2025, and UN 2024 columns present and the footnote markers ([n 1]) preserved as text. World GDP reads 128,003,776 million USD in the IMF column; the United States reads 32,642,373. From there pd.read_html("gdp.html", encoding="utf-8") returns a 222×4 DataFrame, country names and figures intact. Pass that encoding argument: without it, pandas mangles Wikipedia’s non-breaking spaces into  garbage in every cell that has one.

The general rule: markdown for prose, HTML for structure. If your destination is an LLM pipeline, this split matters enough that we wrote a whole comparison of markdown vs HTML for LLMs.

When you don’t need a scraper at all

Three keyless APIs cover the cases where a scraper is overkill, and all three work from any HTTP client, no token, no registration.

The summary endpoint is one call per article:

$ curl -s "https://en.wikipedia.org/api/rest_v1/page/summary/Web_scraping"
{"type":"standard","title":"Web scraping",
 "wikibase_item":"Q665452","pageid":2696619,
 "description":"Method of extracting data from websites",
 "extract":"Web scraping, web harvesting, or web data extraction is...", ...}

Abridged, but real: description, lead extract, thumbnail URL, page ID, and that Wikidata ID again, all in one call. When you need metadata for ten thousand articles, this endpoint is the difference between an afternoon and a month of parsing.

The Action API extracts module returns plaintext with no HTML at all, which sidesteps the cleaning question completely:

$ magpie scrape "https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=Mount_Fuji&format=json&explaintext=1&exintro=1" --page-format raw

The extract opens: “Mount Fuji (富士山・富士の山, Fujisan, Fuji no Yama) is an active stratovolcano located on the Japanese island of Honshu, with a summit elevation of 3,776.24 m (12,389 ft 3 in).” Drop exintro for the whole article in plaintext.

The media-list endpoint enumerates every image on a page; Mount Fuji returns 19 items with file titles and types. Between the three, the only reason left to scrape rendered HTML is the thing the APIs don’t ship: rendered tables and infoboxes, which the previous two sections handle.

Crawling Wikipedia without tripping the wire

This is the section where I lost pages so you don’t have to. A naive three-page crawl from the Web scraping article, --max-pages 3 --max-depth 1, finished with pages_ok=1 pages_err=2. The seed scraped fine; two discovered URLs errored. The culprits: Wikipedia’s section-edit links point at /w/index.php?action=edit&section=N, and /w/ is robots-disallowed, so Magpie’s crawler refused them exactly as designed. The site effectively punishes crawlers that follow everything.

The fix is one flag that keeps the crawl on article space:

$ magpie crawl "https://en.wikipedia.org/wiki/Web_scraping" \
    --max-pages 4 --max-depth 1 --corpus --no-sitemap \
    --path-prefix "/wiki/" --out corpus.jsonl
crawl: run_id=5f77e9162ae84cd1-42228 pages_ok=4 pages_err=0 records=4

Four pages, zero errors, one JSONL record each: Web scraping (3,376 words), API (3,274), Academic journal publishing reform (3,391), American Airlines (2,663). Corpus mode costs zero LLM calls and no API key. --no-sitemap is required in spirit here, since the sitemap 403s anyway. The same recipe transfers to any site with a clean URL namespace; the site scraper hub indexes every site we’ve tested this way.

For anything bigger than a targeted crawl, don’t scrape at all. Wikimedia publishes complete database dumps at dumps.wikimedia.org: every article, full revision history, multigigabyte compressed files, sanctioned for exactly this purpose. A wikipedia scraper is the right tool for live, targeted, or on-demand data; the dumps are the right tool for bulk. If your actual goal is historical snapshots rather than current articles, the Wayback Machine has its own API and its own quirks, which we tested separately.

FAQ

The content is public and freely licensed under CC BY-SA 4.0, and robots.txt permits article pages. The real obligation is licensing: republished text needs attribution and a share-alike license. This is general information, not legal advice.

Does Wikipedia block scrapers?

Not at polite rates. I made roughly 35 requests across articles, APIs, wikitext, and three crawl runs, spaced a few seconds apart, and never saw a challenge, rate limit, or block. The robots preamble warns that abusive crawlers get blocked, and the /trap/ honeypot exists for robots violators.

Why is the infobox missing from my scraped markdown?

Cleaning heuristics classify infoboxes as boilerplate and drop them, correctly for article use and wrongly for yours. Fix: scrape with --include ".infobox" --page-format html, or take ?action=raw wikitext and parse the pipe syntax.

Should I use the Wikipedia API or a scraper?

APIs for metadata, summaries, plaintext extracts, and media lists; rendered HTML for tables and infoboxes; wikitext for structured field parsing at scale; dumps for bulk. Most projects need exactly two of the four.

Can I download all of Wikipedia?

Yes, and you should instead of scraping it: dumps.wikimedia.org ships the complete English Wikipedia as compressed multigigabyte files, updated regularly, built for bulk download. Scrape only the live slices the dumps can’t give you.

Stop renting credits.

One flat price, your machine, your keys.

Download free for Windows, macOS and Linux

Windows · macOS · Linux $49/mo flat, cancel anytime