Claude
Skills
Sign in
Back

scraper-builder

Included with Lifetime
$97 forever

Build production-ready web scrapers for any website using Bright Data infrastructure. Guides you through site analysis, API selection, selector extraction, pagination handling, and complete scraper implementation. Use this skill whenever the user wants to build a scraper, create a crawler, extract data from a website, scrape product pages, handle pagination, build a data pipeline from a web source, or automate data collection from any site — even if they don't explicitly say 'scraper'. Triggers on phrases like 'build a scraper for', 'scrape data from', 'extract products from', 'crawl pages on', 'get data from [website]', or 'I need to pull data from'.

Backend & APIs

What this skill does


# Scraper Builder

You are building a production-ready web scraper for the user. Your job is to guide them from "I want data from site X" to a working, robust scraper that handles real-world challenges like pagination, dynamic content, anti-bot protection, and data parsing.

## Critical: Always Validate Your Output

After building the scraper, **always run it** on a small sample (1-3 pages) and show the extracted data to the user before scaling up. If the output is empty, malformed, or missing fields, iterate — fix selectors, switch APIs, or adjust the parsing logic. A scraper that doesn't produce clean data is not done.

Take your time with the reconnaissance phase. Spending 2 minutes analyzing the HTML upfront prevents hours of debugging later. Quality is more important than speed here.

## How This Skill Works

This skill orchestrates Bright Data's four APIs to build scrapers intelligently. Rather than writing fragile custom scraping code, you analyze the target site first, then pick the most reliable and cost-effective extraction method. The decision tree is:

1. **Does a pre-built scraper already exist?** → Use Web Scraper API (zero parsing code needed)
2. **Is the page static / no interaction needed?** → Use Web Unlocker API (cheapest, simplest)
3. **Does the page need clicks, scrolls, or JS interaction?** → Use Browser API (full automation)
4. **Need search engine results?** → Use SERP API

The skill produces complete, runnable code — not pseudocode or outlines.

---

## Phase 1: Understand the Target

Before writing any code, you need to understand what the user wants and what the site looks like. Ask these questions (skip any the user already answered):

1. **What site?** — The target URL or domain
2. **What data?** — Which fields they need (product names, prices, reviews, etc.)
3. **What scope?** — Single page, category pages, search results, entire site section?
4. **Pagination?** — Do they need to scrape across multiple pages?
5. **Volume?** — Roughly how many items/pages? (affects sync vs async choice and concurrency strategy — see [references/concurrency-guide.md](references/concurrency-guide.md))
6. **Output format?** — JSON, CSV, database? (default to JSON if unspecified)
7. **Language preference?** — Python or Node.js? (default to Python if unspecified)

Don't over-interview. If the user says "build a scraper for Amazon product pages", you already know: site=Amazon, data=product details, scope=product pages. Jump ahead.

---

## Phase 2: Check for Pre-Built Scrapers

Before doing any custom work, check if Bright Data already has a scraper for this domain. This is the fastest, cheapest, and most reliable path.

Read [references/supported-domains.md](references/supported-domains.md) for the curated list of common pre-built scrapers. But the curated list may not be complete — Bright Data supports 100+ domains and adds new scrapers regularly. If you don't see the target domain in the curated list, **query the live Dataset List API** to check:

```bash
curl -H "Authorization: Bearer $BRIGHTDATA_API_KEY" \
     https://api.brightdata.com/datasets/list
```

This returns every available scraper with its `dataset_id` and name. Search the results for the target domain. You can also browse the full documentation index at `https://docs.brightdata.com/llms.txt` to discover scraper-specific docs and supported parameters.

### If a pre-built scraper exists

Use the Web Scraper API or Python SDK platform-specific scrapers. This gives you structured JSON with no parsing code needed.

**Python SDK approach (preferred):**
```python
from brightdata import BrightDataClient

async with BrightDataClient() as client:
    result = await client.scrape.amazon.products(url="https://amazon.com/dp/B0CRMZHDG8")
    if result.success:
        print(result.data)  # Structured product data
```

**REST API approach (shell/curl):**
```bash
bash scripts/datasets.sh amazon_product "https://www.amazon.com/dp/B09V3KXJPB"
```

For bulk scraping with pre-built scrapers, use the async trigger/poll/fetch pattern:
```python
async with BrightDataClient() as client:
    # Trigger without waiting
    job = await client.scrape.amazon.products_trigger(url=url)
    # Poll until ready
    await job.wait(timeout=180, poll_interval=10, verbose=True)
    # Fetch results
    data = await job.fetch()
```

Skip to Phase 5 (pagination/orchestration) if the user needs multi-page scraping with a pre-built scraper.

### If no pre-built scraper exists

Continue to Phase 3 — you need to analyze the site and build a custom scraper.

---

## Phase 3: Site Reconnaissance

This is the critical step that separates reliable scrapers from brittle ones. You need to understand the site's structure before writing extraction code.

### Step 3a: Fetch the page HTML

Use Web Unlocker to get the raw HTML. This tells you whether the content is server-rendered or client-rendered, and gives you the actual DOM to analyze.

```python
import requests
import os

API_KEY = os.environ["BRIGHTDATA_API_KEY"]
ZONE = os.environ["BRIGHTDATA_UNLOCKER_ZONE"]

response = requests.post(
    "https://api.brightdata.com/request",
    headers={"Authorization": f"Bearer {API_KEY}"},
    json={
        "zone": ZONE,
        "url": "https://target-site.com/page",
        "format": "raw"
    }
)
html = response.text
```

Or use the scrape skill's shell script:
```bash
bash skills/scrape/scripts/scrape.sh "https://target-site.com/page"
```

### Step 3b: Analyze the HTML structure

Read [references/site-analysis-guide.md](references/site-analysis-guide.md) for the detailed analysis playbook.

Look at the fetched HTML and determine:

1. **Is the content in the HTML?** If the data you need is present in the raw HTML, Web Unlocker is sufficient. If the HTML is mostly empty shells with JS framework markers (`<div id="root"></div>`, `<div id="__next"></div>`, `ng-app`), the content is client-rendered and you need Browser API.

2. **Identify reliable selectors.** Find the CSS selectors or data attributes that target the data fields. Prefer selectors in this order (most reliable → least):
   - `data-*` attributes (e.g., `[data-testid="product-price"]`) — survive redesigns
   - Semantic HTML with specific classes (e.g., `.product-card .price`)
   - `id` attributes — unique but may change
   - Structural selectors (e.g., `div > span:nth-child(2)`) — fragile, avoid

3. **Identify the data pattern.** Is it:
   - **List page** — multiple items in a repeating structure (product grid, search results)
   - **Detail page** — single item with many fields (product page, profile)
   - **Paginated** — multiple pages of results with next/prev controls
   - **Infinite scroll** — content loads on scroll (needs Browser API)
   - **API-backed** — check the Network tab pattern; some sites fetch data from JSON APIs

4. **Check for hidden APIs.** Many modern sites load data via XHR/fetch calls to internal APIs. If you see structured JSON endpoints in the page source or network activity, hitting those directly through Web Unlocker is often cleaner than parsing HTML.

### Step 3c: Decide the extraction approach

Based on your analysis:

| Finding | Approach |
|---------|----------|
| Content in HTML, no interaction needed | **Web Unlocker** — fetch HTML, parse with BeautifulSoup/Cheerio |
| Content loaded via JSON API | **Web Unlocker** — hit the API endpoint directly |
| Content requires JS rendering | **Browser API** — render then extract |
| Content needs click/scroll/interaction | **Browser API** — automate the interaction |
| Infinite scroll pagination | **Browser API** — scroll and collect |
| Standard URL-based pagination | **Web Unlocker** — iterate page URLs |
| CAPTCHA-heavy site | **Browser API** — auto-solves CAPTCHAs |

---

## Phase 4: Build the Extractor

Now write the actual extraction code. The approach depends on Phase 3's decision.

### Approach A: Web Unlocker + HTML Parsing

Best for static sites or sites with server-rendered HTML. This is th
Files: 6
Size: 79.2 KB
Complexity: 53/100
Category: Backend & APIs

Related in Backend & APIs