Skip to main content

A small extension to Scrapy that provides a WaitRequest for delayed/polling requests.

Project description

scrapy-waitrequests

Hey! This is a library for common problems we encounter when dealing with situations that vanilla Scrapy does not fully cover, so here you can find a lot of useful tools.

Index

  • Wait Request

Wait Request

Wait Request is a method to keep polling for a task's completion—such as a CAPTCHA or batch job—without blocking other requests. You can prepare the initial request along with a function to evaluate whether you have received the desired response. Here is an example:

from scrapy import Spider
from scrapy_algova.wait_request import WaitRequest

class MySpider(Spider):
    name = "my_spider"

    def start_requests(self):
        yield WaitRequest(
            url="https://some.api/endpoint",
            method="POST",
            formdata={"foo": "bar", "captcha_id": "12345"},
            callback=self.parse_result,
            errback=self.handle_error,
            check_condition=self.is_captcha_ready,
            wait_time=3.0,     # Interval (in seconds) before making the next request
            max_tries=5,       # You don't want to check forever, so set a max number of tries
            meta={"info": "extra data"},
            dont_filter=True
        )

    def is_captcha_ready(self, response):
        """
        Check if the response matches what you expect (e.g., a JSON with "status": "OK").
        Otherwise, return False so WaitRequest will retry.
        """
        data = response.json()
        return data.get("status") == "OK"

    def parse_result(self, response):
        """
        Called when 'is_captcha_ready' returns True 
        or when 'max_tries' is reached.
        """
        data = response.json()
        self.logger.info("Task completed! Response data: %s", data)
        # Continue your logic here...

    def handle_error(self, failure):
        """
        Called when there's a network error, a 500 HTTP response, etc.
        """
        self.logger.error("Request failed: %s", failure.value)

This approach is far better than using a busy wait with time.sleep(), an infinite while True, or immediately sending repeated requests without any interval. It keeps the reactor free so that other Scrapy requests can run concurrently.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy_algova-0.3.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapy_algova-0.3.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file scrapy_algova-0.3.1.tar.gz.

File metadata

  • Download URL: scrapy_algova-0.3.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.21 Darwin/24.3.0

File hashes

Hashes for scrapy_algova-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0de95d6bc68635f39192594bae40f30372a38ae2783c27c70748f3d39d1aae36
MD5 0c5906a6feda0b2e25bb04a695d56f2b
BLAKE2b-256 7310c19306ac36763de2dcb45c914e6b8cc9a483fc6053d9e249e148922c4552

See more details on using hashes here.

File details

Details for the file scrapy_algova-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: scrapy_algova-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.9.21 Darwin/24.3.0

File hashes

Hashes for scrapy_algova-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 82c7a9f47c1a0fe8edfa8833e51e3d796c7f885c1b6a63f92e345a01cc0279ba
MD5 9d8877b0b858a731f9f7cd32c91fbd7f
BLAKE2b-256 c00257a4df0dc15a54828681ef930deb997d4d2d1b896f4719ee47563e9879c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page