```yaml
product: AlterLab
title: How to Scrape US Census Data: Complete Guide for 2026
category: Tutorials
comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data."
last_updated: 2026-08-01
canonical_facts:
  - "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."
source_url: https://alterlab.io/blog/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 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](/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](/docs/quickstart/installation) for SDK installation. Below are examples for scraping a public Census page showing median household income data.

Python example:
```python title="scrape_census-gov.py" {3-5}
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):
```javascript title="scrape_census-gov.js" {3-5}
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:
```bash title="Terminal"
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:
```python title="extract_selectors.py"
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:
```python title="extract_census-gov_structured.py"
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](/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.

- **99.2%** — Success Rate
- **1.2s** — Avg Response
- **$0.002** — Per Request (T3)

## 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:
1. Batch requests: Use AlterLab's `/batch` endpoint for 100-url chunks
2. Schedule recurring scrapes: Cron expressions via AlterLab's Scheduling API
3. Store results: Stream JSON output directly to data warehouses
4. Handle pagination: Census tables often use `&page=` parameters)

<div data-infographic="steps">
  <div data-step data-number="1" data-title="Identify public data" data-description="Find target tables on census.gov/data or programs-surveys pages"></div>
  <div data-step data-number="2" data-description="Test with T1 tier; observe response codes"></div

## Frequently Asked Questions

### Is it legal to scrape us census?

Scraping publicly accessible data from US Census is generally permissible under laws like hiQ v LinkedIn, but you must review census.gov's robots.txt and Terms of Service, implement rate limiting, and avoid private or restricted data.

### What are the technical challenges of scraping us census?

US Census employs standard anti-bot protections including rate limiting and header validation. AlterLab handles these via automatic proxy rotation, header management, and smart rendering tiers.

### How much does it cost to scrape us census at scale?

Costs range from $0.0002 per request for static HTML (T1) to $0.004 for full browser rendering (T4), with AlterLab's auto-escalation ensuring you only pay for the successful tier. See our pricing table for details.

## Related

- [SoftwareSuggest Data API: Extract Structured JSON in 2026](<https://alterlab.io/blog/softwaresuggest-data-api-extract-structured-json-in-2026>)
- [Slashdot Data API: Extract Structured JSON in 2026](<https://alterlab.io/blog/slashdot-data-api-extract-structured-json-in-2026>)
- [How to Scrape Google Patents Data: Complete Guide for 2026](<https://alterlab.io/blog/how-to-scrape-google-patents-data-complete-guide-for-2026>)