
How to Scrape US Census Data: Complete Guide for 2026
This guide covers extracting publicly accessible data. Always review a site's robots.txt and Terms of Service before scraping. TL;DR To scrape US Census...
AlterLab handles this automatically — scrape any URL with one API call. No infrastructure required.
Try it freeThis guide covers extracting publicly accessible data. Always review a site's robots.txt and Terms of Service before scraping.
Run a live request from this page. No sign-up needed.
TL;DR
To scrape US Census data in 2026, use AlterLab's API with automatic tier escalation. Start with T1 for static pages, then let the API promote to T3/T4 as needed for anti-bot protections. Extract structured data via CSS selectors or Cortex AI for typed JSON output.
Why collect government data from US Census?
Government data provides reliable foundations for analysis. Common use cases include:
- Market researchers tracking demographic shifts for product expansion planning
- Analysts correlating housing statistics with economic indicators
- Developers building public policy tools that require authoritative population data
Technical challenges
US Census implements standard anti-bot measures: rate limiting by IP, User-Agent validation, and JavaScript challenges on dynamic pages. Raw HTTP requests often fail with 403 or 429 responses. AlterLab's Smart Rendering API automatically handles these via rotating residential proxies, realistic browser fingerprints, and tiered rendering approaches—escalating only when necessary to avoid overpaying for simple pages.
Quick start with AlterLab API
See the Getting started guide for SDK installation. Below are examples for scraping a public Census page showing median household income data.
Python example:
from alterlab import AlterLabSync
client = AlterLabSync("YOUR_API_KEY")
response = client.scrape("https://www.census.gov/programs-surveys/acs/")
print(response["content"])Node.js example (MUST include this):
import { AlterLab } from "alterlab";
const client = new AlterLab({ apiKey: "YOUR_API_KEY" });
const response = await client.scrape({ url: "https://www.census.gov/programs-surveys/acs/" });
console.log(response.text);cURL example:
curl -X POST https://api.alterlab.io/v1/scrape \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.census.gov/programs-surveys/acs/"}'Extracting structured data
For the ACS program page, target these visible elements:
- Program title:
h1.usa-heading-lg - Description:
.usa-prose p:nth-of-type(1) - Last updated:
.usa-tag(contains "Updated" text)
Use AlterLab's selector API to extract these:
from alterlab import AlterLabSync
client = AlterLabSync("YOUR_API_KEY")
result = client.scrape(
url="https://www.census.gov/programs-surveys/acs/"
)
print(result["filtered_content"])Structured JSON extraction with Cortex
For typed data extraction without manual selectors, use Cortex. This example extracts key metrics from a Census data table:
from alterlab import AlterLabSync
client = AlterLabSync("YOUR_API_KEY")
result = client.scrape(
url="https://data.census.gov/table/ACSST1Y2022.S1901?q=median+income",
extraction_schema={
"type": "object",
"properties": {
"median_household_income": {"type": "number"},
"margin_of_error": {"type": "number"},
"geography": {"type": "string"},
"year": {"type": "integer"}
}
}
)
print(result["filtered_content"]) # Typed JSON output: {"median_household_income": 74580, ...}Cost breakdown
US Census pages typically require T3 (Stealth) due to header validation and light JS challenges. AlterLab auto-escalates tiers—you start at T1 and only pay for the successful tier. See AlterLab pricing for full details.
| Tier | Use Case | Cost per Request | Cost per 1,000 | Requests per $1 |
|---|---|---|---|---|
| T1 — Curl | Static HTML, no JS needed | $0.0002 | $0.20 | 5,000 |
| T2 — HTTP | Standard pages with headers | $0.0003 | $0.30 | 3,333 |
| T3 — Stealth | Protected pages, anti-bot active | $0.002 | $2.00 | 500 |
| T4 — Browser | Full JS rendering required | $0.004 | $4.00 | 250 |
| T5 — CAPTCHA | CAPTCHA solving + JS rendering | $0.02 | $20.00 | 50 |
Note: For most Census pages, expect T3 usage ($0.002/request). Auto-escalation prevents wasted spend—T1/T2 attempts that fail don't incur charges.
Best practices
- Respect
census.gov/robots.txt: disallow paths like/api/but allow/programs-surveys/ - Implement rate limiting: 1 request/second per IP to avoid triggering protections
- Handle dynamic content: AlterLab's T4 tier renders JS-heavy tables; use
wait_for_network_idle=true - Rotate User-Agents: AlterLab does this automatically via proxy pools
- Monitor responses: check for 429/403 and adjust concurrency
Scaling up
For large datasets:
- Batch requests: Use AlterLab's
/batchendpoint for 100-url chunks - Schedule recurring scrapes: Cron expressions via AlterLab's Scheduling API
- Store results: Stream JSON output directly to data warehouses
- Handle pagination: Census tables often use
&page=parameters)
Was this article helpful?
Frequently Asked Questions
Related Articles

Oxylabs Alternative: Practical Developer Guide for Web Scraping Pipelines
Build reliable scraping pipelines with anti-bot handling, auto-escalation, and monitoring using a practical AltLab-compatible solution. Follow the 3-step setup, integrate with your existing workflow, and control costs at $0.0002 per request.
Herald Blog Service

Python aiohttp vs. httpx for High-Throughput Web Scraping
A benchmark‑driven comparison of aiohttp and httpx for asynchronous scraping, with concrete numbers, code snippets, and guidance on when to choose each library.
Herald Blog Service

MCP Servers Explained: How AI Tools Access the Real-Time Web in 2026
Learn how Model Context Protocol servers enable AI agents to fetch live data via scraping APIs, with architecture, code examples, and best practices for 2026.
Herald Blog Service
Popular Posts
Recommended

Selenium Bot Detection: Why You Get Flagged and How to Fix It

Why Your Headless Browser Gets Detected (and How to Fix It)

Mastering Playwright Stealth for Agentic Web Workflows

How to Scrape E-Commerce Sites for AI Agents Using Playwright and LLMs

How to Bypass Cloudflare Bot Protection with Puppeteer in 2026
Newsletter
Scraping insights and API tips. No spam.
Recommended Reading

Selenium Bot Detection: Why You Get Flagged and How to Fix It

Why Your Headless Browser Gets Detected (and How to Fix It)

Mastering Playwright Stealth for Agentic Web Workflows

How to Scrape E-Commerce Sites for AI Agents Using Playwright and LLMs

How to Bypass Cloudflare Bot Protection with Puppeteer in 2026
Stay in the Loop
Get scraping insights, API tips, and platform updates. No spam — we only send when we have something worth reading.
Explore AlterLab
Anti-Bot Handling API
Automatic challenge handling for protected sites — works out of the box.
JavaScript Rendering API
Render SPAs and dynamic content with headless Chromium.
Pricing
5-tier pricing from $0.0002/page. Up to 5,000 free requests to start.
Documentation
API reference, SDKs, quickstart guides, and tutorials.
Web Scraping API Resources
Part of the Web Scraping API Documentation cluster
Complete API reference with 5-tier auto-escalation — Curl to challenge resolution.
Pillar pageConfigure Tier 4 browser rendering for SPAs and dynamic content.
Scrape pages behind login using session management.
Real success rates and cost data across all 5 tiers.
MCP Server, Python SDK, and Firecrawl-compatible API for AI agent workflows.