Stack Overflow Scraper: Questions, Answers and Comments avatar

Stack Overflow Scraper: Questions, Answers and Comments

Pricing

from $0.50 / 1,000 questions

Go to Apify Store
Stack Overflow Scraper: Questions, Answers and Comments

Stack Overflow Scraper: Questions, Answers and Comments

Scrape Stack Overflow and every Stack Exchange site through the official API: questions by tag, search or URL with answers and comments, bodies in HTML, plain text and Markdown, score, views, tags, accepted answer, author and CC BY-SA attribution.

Pricing

from $0.50 / 1,000 questions

Rating

0.0

(0)

Developer

ZH Tech

ZH Tech

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

2 days ago

Last modified

Features

Limited permissions

Share

Stack Overflow Scraper: questions, answers and comments from any Stack Exchange site

Scrape Stack Overflow and every other Stack Exchange site (Super User, Server Fault, Ask Ubuntu, Mathematics, Unix & Linux, Database Administrators, Data Science and about 180 more) into clean JSON, CSV or Excel. Get questions by tag, by search query or by URL, with their answers (accepted answer first) and comments, bodies in HTML, plain text and Markdown, score, views, tags, accepted answer, author, dates, links and a ready made CC BY-SA attribution line on every row.

The actor uses the official Stack Exchange API v2.3, the sanctioned way to read the network by program. No login, no page scraping, no browser. Up to 100 questions with their full answer and comment threads come back in a single API request, so even the free API quota goes a long way.

What can this Stack Overflow scraper do?

You give itYou get
Tags (python, c#, google-sheets) on any siteThe questions of each tag, sorted by votes, activity, newest, hot, week or month. Several tags as separate queries, or only questions that carry all of them
Search queries (async await deadlock), optionally inside some tagsThe matching questions, sorted by relevance, votes, activity or newest
Question URLs, short links, answer links or IDs, from any mix of sitesExactly those questions. Answer links are resolved to their question
Answers and comments on or offEach question with its top answers (accepted first, then by score) and the comments of the question and of each answer
FiltersDate range, min score, min answers, min views, accepted answer yes or no, open or closed, title contains, excluded tags

Fields on every question row: site, siteName, questionId, title, link, shareLink, tags, score, upVoteCount, downVoteCount, viewCount, favoriteCount, answerCount, commentCount, isAnswered, hasAcceptedAnswer, acceptedAnswerId, acceptedAnswerLink, acceptedAnswer (short summary with text), isClosed, closedReason, closedDate, bountyAmount, bountyClosesDate, owner (name, user ID, reputation, profile link, avatar), lastEditor, creationDate, lastActivityDate, lastEditDate, communityOwnedDate, lockedDate, protectedDate, migratedTo, migratedFrom, bodyText, bodyHtml, bodyMarkdown, contentLicense, attribution, answers, comments, answersIncluded, input, query, scrapedAt.

Answer fields: answerId, questionId, isAccepted, score, upVoteCount, downVoteCount, owner, lastEditor, creationDate, lastActivityDate, lastEditDate, commentCount, link, shareLink, bodyText, bodyHtml, bodyMarkdown, contentLicense, attribution, comments.

Why this actor

  • Official API, nothing to break. No HTML parsing, no blocked pages, no CAPTCHA. Stack Overflow's website forbids crawlers in its robots.txt; this actor never loads a site page and only talks to api.stackexchange.com.
  • Full threads for the price of one request. Answers and comments come nested in the same API call as up to 100 questions. Other tools spend one request per question for answers and run out of quota quickly.
  • Three body formats. HTML for display, clean plain text for analysis (code blocks kept verbatim, links as text and URL), and the original Markdown.
  • Attribution built in. Every question, answer and comment carries its link, author, author profile, license (CC BY-SA 2.5, 3.0 or 4.0) and a ready made attribution sentence, so you can meet the license terms without extra work.
  • Quota aware. The actor honors the API's backoff instructions, waits out short throttles, stops cleanly with a plain message when the daily quota is used up, and reports the remaining quota in the status and run summary.
  • Your own free API key, optional. Without a key the API allows 300 requests per day per IP address. Add a free key and you get 10,000 per day.
  • Fair billing. You pay per question and per answer you get. Comments are free. Duplicates (a question found by two tags), filtered questions and error rows are never charged. Invalid input stops the run before the start fee.

Use cases

  • Developer research and DevRel: see what people ask about your library, API or competitor, which questions stay unanswered, and which answers the community trusts.
  • Product and documentation gaps: collect the most viewed questions in your tag and turn them into docs, FAQ entries or tutorials.
  • Support monitoring: run every hour with sort Newest and a date filter, and push new questions in your tags to Slack, email or a ticket system.
  • Technology trend analysis: compare tags by question volume, views and answer rates over time.
  • Hiring and community: find the people who answer well in a niche (public profile links and reputation only).
  • Knowledge bases and internal search: pull accepted answers with their text and links into your own help tools, with attribution (see the licensing section first).

How to use

  1. Pick What to scrape: Questions by tag, Search, or Question URLs or IDs.
  2. Enter the Site (default stackoverflow), then your tags, queries or URLs.
  3. Choose the Sort and Max questions per tag or query.
  4. Decide on answers (and how many per question) and comments.
  5. Optionally add filters and your free API key.
  6. Click Start. Results appear in the Questions, Answers and Errors views and can be exported as JSON, CSV, Excel, XML or HTML.

Input examples

The prefilled example: the 20 top voted questions in the web-scraping tag, each with its accepted (or best) answer. One API request.

{
"mode": "tags",
"site": "stackoverflow",
"tags": ["web-scraping"],
"maxQuestionsPerQuery": 20,
"maxAnswersPerQuestion": 1
}

Search inside a tag, with three answers and all comments per question:

{
"mode": "search",
"searchQueries": ["async await deadlock"],
"searchTags": ["c#"],
"sort": "relevance",
"maxQuestionsPerQuery": 50,
"maxAnswersPerQuestion": 3,
"includeComments": true
}

Newest questions that carry both python and pandas, asked in the last 7 days (good for a schedule):

{
"mode": "tags",
"tags": ["python", "pandas"],
"tagMatch": "all",
"sort": "creation",
"fromDate": "7 days",
"maxQuestionsPerQuery": 500
}

Specific questions from different sites, answer links included:

{
"mode": "urls",
"questionUrls": [
"https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array",
"https://stackoverflow.com/a/11227902",
"https://math.stackexchange.com/q/11",
"https://superuser.com/questions/1"
],
"maxAnswersPerQuestion": 5,
"includeComments": true
}

Other sites and filters: well viewed, open probability questions on Mathematics with an accepted answer, no answers included:

{
"mode": "tags",
"site": "math",
"tags": ["probability"],
"acceptedAnswer": "yes",
"minAnswers": 2,
"minViews": 1000,
"closedStatus": "open",
"includeAnswers": false
}

Spreadsheet friendly layout, one row per answer:

{
"mode": "tags",
"site": "superuser",
"tags": ["windows-11"],
"sort": "week",
"maxAnswersPerQuestion": 3,
"outputMode": "separate"
}

Output example

A question row in the default nested layout (long texts shortened, user names replaced):

{
"type": "question",
"site": "stackoverflow.com",
"siteName": "Stack Overflow",
"questionId": 58960005,
"title": "async/await deadlock when using WindowsFormsSynchronizationContext in a console app",
"link": "https://stackoverflow.com/questions/58960005/async-await-deadlock-when-using-windowsformssynchronizationcontext-in-a-console",
"shareLink": "https://stackoverflow.com/q/58960005",
"tags": ["c#", "async-await"],
"score": 6,
"upVoteCount": 7,
"downVoteCount": 1,
"viewCount": 1227,
"answerCount": 3,
"commentCount": 4,
"isAnswered": true,
"hasAcceptedAnswer": true,
"acceptedAnswerId": 58960850,
"acceptedAnswerLink": "https://stackoverflow.com/a/58960850",
"acceptedAnswer": {
"answerId": 58960850,
"score": 3,
"ownerName": "answer_author",
"ownerLink": "https://stackoverflow.com/users/11178549/...",
"creationDate": "2019-11-20T18:11:25.000Z",
"bodyText": "This happens because the WindowsFormsSynchronizationContext ...",
"link": "https://stackoverflow.com/questions/58960005/.../58960850#58960850"
},
"isClosed": false,
"closedReason": null,
"owner": {
"userId": 162641,
"displayName": "question_author",
"reputation": 2666,
"userType": "registered",
"link": "https://stackoverflow.com/users/162641/..."
},
"creationDate": "2019-11-20T17:18:43.000Z",
"lastActivityDate": "2019-12-16T09:37:59.000Z",
"bodyText": "As a learning exercise, I'm trying to reproduce an async/await deadlock ...",
"bodyHtml": "<p>As a learning exercise, I'm trying to reproduce ...",
"bodyMarkdown": "As a learning exercise, I'm trying to reproduce ...",
"contentLicense": "CC BY-SA 4.0",
"contentLicenseInferred": true,
"attribution": "\"async/await deadlock when using WindowsFormsSynchronizationContext in a console app\" by question_author, Stack Overflow, https://stackoverflow.com/q/58960005, licensed under CC BY-SA 4.0",
"comments": [
{
"commentId": 104175377,
"postId": 58960005,
"score": 0,
"creationDate": "2019-11-20T17:23:58.000Z",
"owner": { "userId": 3346583, "displayName": "commenter", "reputation": 9760 },
"bodyText": "My standing advice is ...",
"link": "https://stackoverflow.com/questions/58960005/...#comment104175377_58960005",
"contentLicense": "CC BY-SA 4.0"
}
],
"answers": [
{
"answerId": 58960850,
"questionId": 58960005,
"isAccepted": true,
"score": 3,
"owner": { "userId": 11178549, "displayName": "answer_author", "reputation": 47198 },
"creationDate": "2019-11-20T18:11:25.000Z",
"commentCount": 2,
"link": "https://stackoverflow.com/questions/58960005/.../58960850#58960850",
"shareLink": "https://stackoverflow.com/a/58960850",
"bodyText": "This happens because the WindowsFormsSynchronizationContext ...",
"bodyHtml": "<p>This happens because the <a href=...",
"bodyMarkdown": "This happens because the ...",
"contentLicense": "CC BY-SA 4.0",
"attribution": "Answer to \"async/await deadlock when using WindowsFormsSynchronizationContext in a console app\" by answer_author, Stack Overflow, https://stackoverflow.com/a/58960850, licensed under CC BY-SA 4.0",
"comments": []
}
],
"answersIncluded": 1,
"input": "async await deadlock",
"query": "search \"async await deadlock\" in [c#]",
"scrapedAt": "2026-11-22T01:51:45.757Z"
}

An error row (never charged):

{
"type": "error",
"input": "https://stackoverflow.com/questions/tagged/python",
"errorCode": "INVALID_INPUT",
"error": "\"https://stackoverflow.com/questions/tagged/python\" is a tag page, not a question. Put the tag \"python\" into Tags and the site \"stackoverflow.com\" into Site instead."
}

Error codes: INVALID_INPUT (not a question URL or ID), NOT_FOUND (deleted question or answer, or an ID from another site), SITE_NOT_FOUND, QUOTA_EXHAUSTED, KEY_INVALID, THROTTLED, BAD_PARAMETER, FAILED.

Licensing and attribution (please read)

Questions, answers and comments on Stack Exchange are written by their users and licensed under Creative Commons Attribution ShareAlike (CC BY-SA), version 2.5, 3.0 or 4.0 depending on the date of the post. The Stack Exchange API Terms of Use require that applications visibly show that Stack Exchange is the source of the content. If you publish or share the content, attribution means:

  1. Name the source site (for example Stack Overflow).
  2. Link to the original question or answer (link or shareLink).
  3. Show the author's name and link to the author's profile (owner.displayName, owner.link).
  4. Keep the license and share adaptations under the same license (contentLicense).

The attribution field on every row contains all of this as one sentence. For apps without a browser, plain text URLs are enough.

The Stack Exchange Acceptable Use Policy also says that automated collection may not be used to build a similar or competing Q&A website or service, or to develop, train, test, index, benchmark or improve generative AI, chatbots, large language models or machine learning models, without Stack Exchange's written consent (for example a data license from Stack Overflow). Do not use the data for those purposes unless you have that consent. You are responsible for how you use the data. Read the API Terms of Use, the Terms of Service and the Acceptable Use Policy at stackoverflow.com/legal before large or commercial projects.

API quota and your free API key

The Stack Exchange API counts requests per IP address: 300 per day without a key, 10,000 per day with a key. On Apify the IP address of a run is shared with other users, so the free 300 can already be partly used when your run starts. Each request returns up to 100 questions with their answers and comments, so the default run uses 1 request and 1,000 questions use about 10.

To get a key (free, takes two minutes): log in to stackapps.com with any Stack Exchange account, open stackapps.com/apps/oauth/register, fill in an application name and any domain (for example localhost), and copy the Key shown afterwards (not the client secret). Paste it into Stack Exchange API key. The field is stored encrypted.

Without a key the API also stops at page 25 of every query (2,500 questions). When the quota is used up, the run stops with a clear message, keeps everything it already saved, and tells you when more requests are available.

Pricing

Pay per event, you only pay for what is delivered:

  • Actor start: a small flat fee once per run.
  • Question: per question row.
  • Answer: per included answer (nested or as its own row).

Comments are free. The current prices are on the Pricing tab. Never charged: error rows, questions skipped by your filters, duplicates found by several tags or queries, answers beyond your Max answers per question, and anything after your max total charge or Max questions is reached. Invalid input stops the run before the start fee.

Typical runs: the prefilled example is 1 start, 20 questions and 20 answers. 1,000 questions with their accepted answers are 1,000 question events and up to 1,000 answer events.

Use with the API, integrations and AI agents

  • API: POST https://api.apify.com/v2/acts/zhtech~stack-overflow-scraper/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN with the JSON input as the body returns the rows in one call. Add &view=questions (or answers, errors) for one row type.
  • Clients: apify-client for JavaScript and Python. Example (JavaScript): await client.actor('zhtech/stack-overflow-scraper').call({ mode: 'search', searchQueries: ['useEffect cleanup'], maxQuestionsPerQuery: 30 }).
  • Schedules and integrations: run it hourly or daily with sort Newest and Asked on or after set to 1 day, then connect Google Sheets, Slack, a webhook, Zapier, Make or n8n.
  • MCP and agents: the actor works as a tool through the Apify MCP server (mcp.apify.com), so Claude, ChatGPT, Cursor and other agents can look up Stack Overflow threads on demand. Keep the attribution with any answer you show, and set a max total charge on the run to cap the cost.

FAQ

Do I need a Stack Overflow account or API key? No. The actor works without any account. A free API key is optional and raises the daily quota from 300 to 10,000 requests.

Which sites are supported? All public Stack Exchange sites and their meta sites: Stack Overflow (and its Russian, Portuguese, Spanish and Japanese versions), Super User, Server Fault, Ask Ubuntu, MathOverflow, Stack Apps and every <name>.stackexchange.com site such as math, unix, dba, datascience, gaming, cooking or english. Use the short name or the domain in Site.

How many answers and comments do I get? All answers of a question are available; Max answers per question decides how many you keep (accepted answer first, then by score). With Include comments on, you get all comments of the question and of each included answer.

Why did my query return no questions? Check the tag spelling (as shown on the site, for example google-sheets, not Google Sheets) and the site. Filters and date ranges can also remove everything. Question volume on Stack Overflow has dropped a lot in recent years, so short date windows in smaller tags can be empty. The run ends with a plain message and no charge for questions.

What happens when the API quota is used up? The run stops cleanly, keeps what it saved, writes a QUOTA_EXHAUSTED error row (free) and says when more requests become available. Add your own free API key to avoid this.

Is HTML, Markdown or plain text better? Plain text (bodyText) is best for reading, search and analysis; code blocks keep their indentation and links show their URL. HTML (bodyHtml) is the rendered post. Markdown (bodyMarkdown) is what the author typed.

Can I monitor new questions? Yes. Schedule the actor with sort Newest and Asked on or after set to the interval of your schedule (for example 1 day), then send new rows to Slack or a sheet.

Can I use the data to train an AI model? Not without written consent from Stack Exchange. Their Acceptable Use Policy forbids using automatically collected content to build or train generative AI, LLM or machine learning tools, or to build a competing Q&A service. See the licensing section.

Is it legal? The actor uses the official public API within its quotas and backoff rules and reads only public content. The content is CC BY-SA licensed and needs attribution when shared. You are responsible for following the Stack Exchange terms and the laws that apply to you, especially for any personal data such as user names.

Limitations

  • Public content only: no deleted posts, private Stack Overflow for Teams content, votes of specific users or anything that needs a login.
  • Without an API key: 300 API requests per day per IP address (shared on Apify) and at most 25 pages (2,500 questions) per query.
  • Search uses Stack Exchange's own search; its relevance ranking is not documented.
  • The API returns no license for most questions; the actor then fills contentLicense from the Stack Exchange license dates (by the latest edit) and sets contentLicenseInferred: true.
  • Sorting by hot, week or month works for tag listings only; filters combined with those sorts are applied after reading, which can use more of the quota.

Support

Found a wrong field or need another data point? Open an issue on the Issues tab with the input you used and it will be looked at quickly.