Enable Zyte API to avoid bans#

Your target domain in this tutorial, toscrape.com, does not ban traffic. However, when targeting other websites, sooner or later you will get bans.

You will now configure your web scraping code to use Zyte API to avoid bans on any website:

  1. Sign up for Zyte API. You get $5 free for a month, and you should only need a fraction of that to complete this tutorial.

  2. Install the latest version of scrapy-zyte-api:

    pip install --upgrade scrapy-zyte-api
  3. Configure scrapy-zyte-api in transparent mode by adding the following code at the end of tutorial/settings.py, replacing YOUR_API_KEY with your API key:

        "http": "scrapy_zyte_api.ScrapyZyteAPIDownloadHandler",
        "https": "scrapy_zyte_api.ScrapyZyteAPIDownloadHandler",
        "scrapy_zyte_api.ScrapyZyteAPIDownloaderMiddleware": 1000,
    REQUEST_FINGERPRINTER_CLASS = "scrapy_zyte_api.ScrapyZyteAPIRequestFingerprinter"

If you run your code again:

scrapy crawl books_toscrape_com -O books.csv

Your code will work the same, only that requests will be sent through Zyte API, to avoid bans cost-efficiently.


If you get an SSL error, install the Zyte CA certificate on your system and try again.