---
name: scrape-public-pages
description: Build and verify small scrapers for permitted public pages, with CSV or JSON output, and save a reusable recipe per site.
---

# Scrape public pages

Before writing code, collect the target URL, required fields, output format,
filename, minimum record count, and one expected value from the user.
Ask for any missing value.

## Known sites first

Take the site's host name (for example `example.com`) and look for `targets/<host>/` in the
current project.

- If `targets/<host>/recipe.md` exists, read it and run `targets/<host>/scrape.py`.
  Then run every check under **Verify after each attempt**. If all pass, deliver.
- If any check fails, say which one and what you saw, then start again from
  **Use this order** and update the recipe when you finish.
- If there is no recipe, start from **Before coding**.

## Before coding

1. Confirm the requested page is public and within the scope I described.
2. Inspect robots.txt and note relevant rules. Treat robots.txt as crawler guidance,
   not as permission by itself.
3. Stop and ask me before continuing if the workflow needs login, personal data,
   CAPTCHA, concealed automation, or access that the site denies.

## Use this order

1. Start with Python Requests and a finite timeout.
2. Verify the response body contains the expected record selector or JSON path.
3. If a normal browser gets the permitted public content but Requests returns an
   incompatible response, try curl_cffi with a current generic browser target.
   Do not create a custom fingerprint or domain-specific evasion profile.
4. Use Playwright only if page JavaScript or a permitted interaction creates the data.
5. If a challenge or explicit denial remains, stop. Do not add CAPTCHA solving,
   proxy rotation, stealth plugins, credential capture, or access-control bypasses.

## Verify after each attempt

- Record requested URL, final URL, status, and content type.
- Reject login, consent, challenge, rate-limit, and generic error pages.
- Require the expected selector or JSON path.
- Require at least the agreed number of accepted records.
- Require every requested field on every accepted record.
- Inspect at least three sample records.
- Run the final scraper twice and confirm the schema stays the same.
- Open the saved CSV or JSON and verify its row count and field names.

## Deliver

- One scraper file with a main entry point.
- requirements.txt with direct dependencies only.
- The saved CSV or JSON file.
- One run command I can copy.
- A short verification summary: chosen method, final URL, accepted record count,
  required-field completeness, and any remaining limitation.

Use one transport in the final script. Remove abandoned code and dependencies.
Prefer stable labels and semantic attributes over long generated CSS class chains.

## Save the recipe

When every check passes, save what worked in `targets/<host>/`:

- `scrape.py`: the final scraper, unchanged.
- `recipe.md`: the URL, the method that worked (Requests, curl_cffi or Playwright) and why
  the lighter ones failed, the selectors or JSON paths, the fields, the expected value,
  the normal record count, and the date of the last successful run.

Keep site-specific values in the recipe, never in this file.
