Integrating WebScrapingAPI with Scrapy in Python

Scrapy is a popular high-level framework used for crawling websites and extracting structured data from them. In this guide, we'll show you how to integrate the powerful framework with WebScrapingAPI so that you can combine Scrapy's capability to build spiders with our API's data extraction functionalities.

A basic example of integrating WebScrapingAPI with Scrapy

Let's say that you want to use the Scrapy framework to send a request through the API to HTTPbin is a good example here because a successful request should return the client's IP. Since WebScrapingAPI automatically rotates proxies, each time you execute the code, you should get a different IP back.

Here's what that code looks like:

import scrapy

class BasicSpider(scrapy.Spider):
	name = 'basic'
	allowed_domains = ['']
	start_urls = ['']

	def parse(self, response):
		file = open('scrapypage.txt', mode='wb')
		print("Scrape done. Check the result in scrapypage.txt file.")

	def start_requests(self):
		url = ''
scraper_url = f'{url}' 
yield scrapy.Request(url=scraper_url, callback=self.parse)

As you can see, you have to use the endpoint, after which you add ?api_key=, your personal key, and &url= followed by the encoded version of the URL you want to scrape, which is The results are saved in the scrapypage.txt file in this example.

After saving the code, all you have to do is execute the following line in your terminal:

scrapy crawl basic
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.