Skip to main content

Python Web Scraper with Error Handling

Generate a production-ready Python web scraper using BeautifulSoup or Scrapy with retry logic, rate limiting, proxy rotation, and structured data output.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt asks the AI to build a production-ready Python web scraper rather than a throwaway script. It specifies seven concrete requirements: parsing with [library], retry logic with exponential backoff capped at [max_retries], rate limiting at [requests_per_second], handling of 403/429/timeout/CAPTCHA errors, structured output as [output_format], rotating-file logging, and pagination up to [max_pages] — all with type hints and docstrings.

The structure works because it front-loads the unglamorous reliability concerns that decide whether a scraper survives unattended. The [target_site_type] and [data_fields] variables tell the AI what to extract and from what shape of page, while [max_retries], [requests_per_second], and [max_pages] give it the operational guardrails — so you get politeness and resilience baked in, not bolted on after the first 429 ban.

When to use it

  • You need a scraper that runs unattended and recovers from transient errors instead of crashing.
  • You're extracting structured [data_fields] from a paginated site and want clean CSV/JSON out.
  • You want rate limiting and backoff in place from the start to stay polite and avoid bans.
  • You need rotating logs so a long-running scrape is debuggable after the fact.
  • You're choosing between BeautifulSoup and Scrapy and want the requirements to drive the choice.

Example output

Expect a complete, runnable Python module: a scraper class or functions using [library], a retry decorator or loop with exponential backoff, a rate limiter, error handlers branching on status codes, and an output writer for [output_format]. Logging is wired through a rotating file handler, pagination loops to [max_pages], and every function carries type hints and docstrings — code you can drop in and configure, not pseudocode.

Pro tips

  • Match [library] to the site: static HTML suits BeautifulSoup + requests, while JS-heavy or large crawls justify Scrapy.
  • Keep [requests_per_second] conservative (the default of 2 is polite) — aggressive rates are what trigger 429s and IP bans.
  • Be specific with [data_fields]; vague fields produce brittle selectors the AI guesses at.
  • Set [max_pages] to a real bound so a runaway loop can't hammer the target indefinitely.
  • Ask for both CSV and JSON in [output_format] if downstream consumers differ — it's cheap to emit both.
  • The prompt mentions CAPTCHA handling but no scraper truly solves CAPTCHAs; treat that as graceful detection and backoff, not bypass.

Frequently Asked Questions

Should I use BeautifulSoup or Scrapy with this prompt?
Set the `[library]` variable to match your target. BeautifulSoup with requests suits static HTML and smaller jobs, while Scrapy is better for large crawls or sites needing concurrency and built-in pipeline features. The prompt adapts to either.
Does this prompt actually solve CAPTCHAs?
No. It includes graceful handling for CAPTCHA encounters, meaning detection and backoff, not automated solving. No general-purpose scraper reliably bypasses CAPTCHAs, so treat that requirement as resilience rather than a guarantee of getting past challenges.
How does it avoid getting the scraper banned?
It implements rate limiting at the `[requests_per_second]` you set plus exponential backoff on retries. Keeping the rate conservative, defaulting to 2 requests per second, makes the scraper polite and far less likely to trigger 429 responses or IP bans.
What output formats can it produce?
Whatever you specify in `[output_format]`, defaulting to both CSV and JSON. The scraper writes structured data so results are usable downstream in spreadsheets, databases, or further processing pipelines without manual reformatting.
Is the generated code production-ready?
It is designed to be, with retry logic, rate limiting, rotating-file logging, error handling, and type hints throughout. You should still review selectors against the live site and test pagination, since page structures vary and change over time.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Python & Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support