
How to Scrape US Census Data: Complete Guide for 2026
Learn how to scrape US Census data ethically and efficiently using Python, Node.js, and AlterLab's API. Handle anti-bot protections and extract structured data.
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.
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:
import alterlab
client = alterlab.Client("YOUR_API_KEY")
response = client.scrape("https://www.census.gov/programs-surveys/acs/")
print(response.text)Node.js example (MUST include this):
import { AlterLab } from "alterlab";
const client = new AlterLab({ apiKey: "YOUR_API_KEY" });
const response = await client.scrape("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" \
-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:
import alterlab
client = alterlab.Client("YOUR_API_KEY")
result = client.scrape(
url="https://www.census.gov/programs-surveys/acs/",
selectors={
"title": "h1.usa-heading-lg",
"description": ".usa-prose p:nth-of-type(1)",
"updated": ".usa-tag:contains('Updated')"
}
)
print(result.data)Structured JSON extraction with Cortex
For typed data extraction without manual selectors, use Cortex. This example extracts key metrics from a Census data table:
import alterlab
client = alterlab.Client("YOUR_API_KEY")
result = client.extract(
url="https://data.census.gov/table/ACSST1Y2022.S1901?q=median+income",
schema={
"type": "object",
"properties": {
"median_household_income": {"type": "number"},
"margin_of_error": {"type": "number"},
"geography": {"type": "string"},
"year": {"type": "integer"}
}
}
)
print(result.data) # 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

How to Scrape Google Patents Data: Complete Guide for 2026
Learn how to scrape Google Patents data using Python and Node.js. This guide covers technical challenges, structured extraction with Cortex AI, and scaling.
Herald Blog Service

How to Scrape Data.gov Data: Complete Guide for 2026
Learn to extract public data from data.gov with Python, Node.js, and AlterLab’s API. Follow best practices, pricing, and structured extraction steps.
Herald Blog Service

Optimizing RAG Pipelines: Using Markdown and Structured JSON to Reduce LLM Token Waste
Learn how to cut LLM token usage in RAG pipelines by outputting Markdown and structured JSON from web scrapers, lowering cost and latency.
Herald Blog Service
Popular Posts
Recommended

How to Scrape AliExpress: Complete Guide for 2026

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

AlterLab vs Firecrawl: In-Depth Review with Benchmarks & Code Examples

How to Scrape Twitter/X Data: Complete Guide for 2026

How to Scrape Cloudflare-Protected Sites in 2026
Newsletter
Scraping insights and API tips. No spam.
Recommended Reading

How to Scrape AliExpress: Complete Guide for 2026

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

AlterLab vs Firecrawl: In-Depth Review with Benchmarks & Code Examples

How to Scrape Twitter/X Data: Complete Guide for 2026

How to Scrape Cloudflare-Protected Sites 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. 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.