Finish these five prompts and you will have a scraping script you can run without babysitting it: selectors that survive a layout change, pagination that stops on its own, and a check that tells you when the data looks wrong. These Claude prompts for web scraping are copy-paste ready, with the [variables] marked.
What’s on this page
- Five prompts covering selectors, pagination, the fetch loop, and checks.
- Each one is written for a script you run yourself, not a hosted service.
- Rate and politeness are handled in the prompts, not left to chance.
- Every prompt marks the [variables] you replace.
The prompts
1. Plan the selectors for a page
I want to extract [fields] from pages shaped like [page description]. Suggest a selector strategy for each field using [library], name the parts of the page most likely to change, and tell me which fields should have a fallback selector. Paste-safe: do not guess exact class names I have not given you.
What it does: Builds a selector plan that accounts for layout changes before you write the loop.
How to use: Replace [fields], [page description], and [library]; add real class names once you inspect the page.
2. Handle pagination and stopping
The site paginates with [pagination style] and has roughly [page count] pages. Write the logic that follows every page and stops cleanly at the end, including the case where the next link is missing. Explain how it detects the final page.
What it does: Prevents the two usual failures: stopping early and looping forever.
How to use: Replace [pagination style] and [page count]; test the stop condition before running a full pass.
3. Write the fetch loop
Write a fetch loop in [language] that requests each page from [base url], parses the fields I listed, and stores the results in [output format]. Add a delay between requests, retry failed requests [number] times, and log the URL of anything that fails so I can check it later.
What it does: Produces a loop that keeps going through ordinary failures instead of dying on the first one.
How to use: Replace [language], [base url], [output format], and [number]; run it against a few pages before a full pass.
4. Add a sanity check on the output
My scraper produces records with these fields: [field list]. Write checks that would catch a broken run: fields that are empty for every row, values that fall outside a plausible range, and a row count that is far lower than expected. Explain what each check means.
What it does: Tells you the run failed rather than letting bad data reach your spreadsheet.
How to use: Replace [field list] with your real columns; run the checks before you use the data.
5. Make the script polite and repeatable
Review this scraper [paste code] and adjust it so it identifies itself, respects [robots policy], delays between requests, and can be safely re-run without duplicating rows. Show me the changes rather than rewriting the whole file.
What it does: Turns a working script into one you would not mind running again tomorrow.
How to use: Replace [robots policy], paste your code, and read the site’s terms before a full run.
How to adapt these prompts
- Give sample HTML for one record so the selectors match reality instead of guesses.
- Always ask for the stop condition explicitly; it is the most common bug.
- Keep the delay in the loop even for small jobs, and increase it if you see errors.
FAQ
Is scraping a site allowed?
It depends on the site. Read its terms and its robots rules first, identify your client, and slow down if you are asked to. If the site offers a data export or an API, use that instead.
How do I keep the script working after a redesign?
Use fallback selectors and checks that notice when a field goes empty. A scraper that fails loudly is easier to fix than one that silently collects nothing.
What if the data loads after the page does?
Then the content is not in the initial HTML. Say so in the prompt and ask for an approach that waits for the data or uses the request the page makes.
Keep going
- More Coding prompts
- 5 Claude Prompts for Python Scripts (Copy & Paste)
- 5 Claude Prompts for SERP Analysis (Copy & Paste)
Want more like this? Browse the full free library at GuPrompt.