Stack Overflow Scraper: Questions & Answers

Live-tested stack overflow scraper guide for 2026: robots.txt now disallows everyone, Cloudflare blocks HTML, and the official API is the clean path.

MMotherlode Lab9 min read
Magpie title card: Stack Overflow Scraper: Questions & Answers

Stack Overflow spent a decade as the friendliest scraping target on the internet: permissive robots.txt, server-rendered HTML, published sitemaps. Late 2026 flipped all three. The robots.txt now reads Disallow: / for every user agent, and I rebuilt my stack overflow scraper path around the one door it left open, the official Stack Exchange API, live-tested on 2026-10-29 from a home connection.

Sites change, so re-test before you lean on the numbers below. All commands use Magpie, a local CLI scraper (free, AGPL/commercial dual license). The legal picture here is unusual: the site disallows all automated crawling in robots.txt, yet it publishes every question and answer under CC BY-SA 4.0 and runs a free official API on a separate host. Is web scraping legal covers the background; I am not a lawyer.

What a stack overflow scraper faces in late 2026

The whole robots.txt is 113 bytes. Here it is, all of it, as served to curl, to Magpie, and to a real Chrome alike:

Line Meaning
User-agent: * every crawler, no exceptions
Content-signal: search=no, ai-train=no requests: no search indexing, no AI training
Disallow: / no page allowed, at any path
License: https://stackoverflow.com/license.xml pointer to the content license

Two things sit oddly together. The file bans all automated crawling, and the license.xml link it points at is an RSL file licensing the entire site under CC BY-SA 4.0. The content is open; the crawling is not.

The ban is new. The Wayback Machine has Stack Overflow’s older robots.txt archived on 2026-04-28 and again on 2026-09-10, and both versions are the classic permissive file: action paths disallowed (/questions/*/answer/submit, /suggested-edits/, /emails/*, that family), everything else allowed, a Sitemap: line at the bottom. By 2026-10-29 the blanket disallow was live. Whatever drove the change, it happened in the weeks between those two dates, and it applies to Google’s crawler in the same line as yours.

The HTML wall, method by method

robots.txt is a request. I checked whether the HTTP layer enforces it. The test URL was question 927358, “How do I undo the most recent local commits in Git?”, fetched from a residential IP with seconds between attempts:

Method Result
curl, default HTTP 403, Cloudflare challenge (robots.txt answers 418)
Magpie static scrape bot challenge (cloudflare), exit 8
Magpie + --header-profile chrome 403, same
Magpie + --render browser challenge interstitial served at status 200, reported blocked
Magpie crawl sitemap.xml 403, seed page 403
Headless Chrome, real UI “Just a moment…” for a few seconds, then the page loads

Read the last row twice, because it defines what kind of wall this is. A real browser session passes the JavaScript challenge on its own, and the question page behind it shows 105 answers and 16.8 million views. Nothing else I tried got through. TLS tricks and header games do not clear a challenge that wants to execute JavaScript and set cookies, and Magpie’s browser render reports the interstitial instead of waiting it out. That is the tool being honest rather than the tool failing.

Crawling is dead three separate ways. The robots.txt disallows everything, so a polite crawler stops before the first request. Magpie’s crawl additionally treats an unfetchable robots.txt as deny-all, per RFC 9309, and Cloudflare 403s the robots fetch itself. And even past those two, every HTML URL, including sitemap.xml, answers with the challenge. The mechanics of polite crawling live in the robots.txt scraping guide; on this site they are not negotiable.

Three doors, one decision

Door Auth Daily budget Returns Best for
Stack Exchange API None, key optional 300/day per IP; 10,000 with free key Typed JSON, full fields Everything bulk, history, search
Magpie stackoverflow vertical None 2 API calls per question One typed question record Pipelines
HTML scraping None Blocked An HTTP 403 page Nothing, in my testing

Door 1: the Stack Exchange API

api.stackexchange.com is a separate host from the walled one, and it answered every request instantly with no key. The throttle rules, from the docs plus live responses:

Rule Value
Anonymous, no key 300 requests/day per IP (my response said quota_max: 300)
With a free key 10,000/day default
Burst ceiling 30 requests/sec per IP; above that, drops plus a short ban
backoff field wait that many seconds before repeating a method
Repeats the API caches heavily; don’t re-ask the identical query within a minute

The key is self-serve: create an app on Stack Apps, pass key= on every call, and the daily quota is the documented 10,000. Every response carries quota_remaining, so a polite client can watch its own budget.

Discovery is an API call, which retires the listing pages the old scrapers crawled. The most-voted git questions:

$ curl -s --compressed "https://api.stackexchange.com/2.3/search/advanced\
?order=desc&sort=votes&tagged=git&site=stackoverflow&pagesize=3" | jq -r \
'.items[] | "\(.score)\t\(.answer_count) answers\t\(.title)"'
27246	105 answers	How do I undo the most recent local commits in Git?
20355	41 answers	How do I delete a Git branch locally and remotely?
14061	37 answers	What is the difference between 'git pull' and 'git fetch'?

Titles arrive HTML-escaped (' above); unescape them at the consumer end.

Answers need filter=withbody (the default filter omits bodies), and one question can spread past a single page. Question 927358 has 105 answers; pagesize=100 returned 100 with has_more: true and the hundredth still scoring 4. Scores, is_accepted, owner objects, dates, view counts, and content_license: "CC BY-SA 4.0" all ride along in the same records. That license is the whole point of the API path: the answers are licensed for reuse, and CC BY-SA’s attribution term means you keep the question link and contributor credit in whatever you build. The Reddit scraper guide covers the sibling site with the same pattern, and the GitHub scraper guide extends it to repos and issues.

Door 2: the Magpie stackoverflow vertical

Magpie ships 27 zero-LLM verticals, and Stack Overflow is one of them. Point a scrape at any stackoverflow.com/questions/{id} URL and the vertical fires, making two API calls under the hood: the question with bodies, then the top-10 answers sorted by votes.

$ magpie scrape "https://stackoverflow.com/questions/927358" \
    --vertical stackoverflow --out q.json
$ jq '.record | {kind, title, score, tags,
    top: (.answers[0] | {score, is_accepted})}' q.json
{
  "kind": "question",
  "title": "How do I undo the most recent local commits in Git?",
  "score": 27246,
  "tags": ["git", "version-control", "git-commit", "undo", "git-reset"],
  "top": { "score": 30178, "is_accepted": true }
}

The record carries the question title, score, tags, body, owner display name, and an answers array where each entry has score, is_accepted, and the body as raw HTML (consumers clean it). Three limits worth knowing before you trust the output. It returns the top 10 answers by votes, which is 10 of 105 on my test question, and it hardcodes that page size. It drops every date, the view count, the answer count, and the accepted-answer ID, all of which the raw API returns. And it covers stackoverflow.com only; the rest of the Stack Exchange network (Server Fault, Super User, Ask Ubuntu) is out of scope by design.

Two small graces: the short URL form without the slug works, and a dead ID fails loudly with vertical: stackoverflow: no question for id instead of returning an empty record. Each question costs 2 of your 300 daily anonymous requests, or 2 of 10,000 with a key.

The honest verdict: the vertical is a pipeline component, not a full mirror. When a typed question record is what you feed to the next stage, it is the fastest path and it needs no key. When you need every answer, dates, or view counts, call the API yourself and keep the vertical for the shape.

Which door, when

Job Use
Question + top answers in a pipeline --vertical stackoverflow
All 105 answers, dates, view counts Raw API with filter=withbody
Discovery by tag, score, or date API search/advanced
Bulk corpus of question pages Nothing. Crawling is barred by robots and Cloudflare alike
Monitoring a question over time API on an interval, respecting backoff

The paid Stack Overflow scrapers on Apify sell convenience at this point, not access: there is no wall for them to break that the API has not already opened. The old HTML-scraping tutorials are now historical documents. Anything they promise, the API delivers with typed fields, a documented quota, and a license that wants the data reused.

FAQ

Is it legal to scrape Stack Overflow? Scraping public pages is generally lawful in the US, but this site’s robots.txt now disallows all automated crawling, and Cloudflare enforces it. The licensed, sanctioned path is the Stack Exchange API, whose content carries CC BY-SA 4.0 attribution terms. I am not a lawyer.

Does Stack Overflow have an official API? Yes. api.stackexchange.com serves questions, answers, users, and search as free JSON. Anonymous access gets 300 requests per day per IP; a free key from Stack Apps raises the default to 10,000.

Why does my scraper get 403 errors on Stack Overflow? The site sits behind Cloudflare bot protection. Plain HTTP clients get a 403 challenge, and header or TLS tricks do not clear it. A real browser passes automatically, but scraping in a browser is crawling with extra steps and still violates the robots.txt.

How do I get all answers to a question? Call https://api.stackexchange.com/2.3/questions/{id}/answers?site=stackoverflow&filter=withbody and paginate with page= while has_more is true. My test question returned 100 of 105 answers on the first call at pagesize=100.

What is Stack Overflow’s rate limit? The API allows 300 requests per day per IP anonymously, 10,000 daily with a free key, 30 requests per second hard ceiling, plus a backoff field on responses. One Magpie vertical call uses 2 requests.

The move that still works

Register the free Stack Apps key (self-serve), then split the work the way the site now demands: search/advanced for discovery, the Magpie vertical for typed question records in a pipeline, raw API calls for anything the record leaves out. The sibling guides cover Hacker News scraping and the full site-by-site list lives in the scrapers for popular websites hub.

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