0Pricing
Python Academy · Lesson

Building a Scrapy Spider

Create a Scrapy project, write a spider, and follow links automatically.

What Is Scrapy?

Scrapy is a full-featured web scraping framework with built-in asynchronous crawling, item pipelines, middlewares, and exporters.

# pip install scrapy

# Create a project:
# scrapy startproject myspider

# myspider/
#   scrapy.cfg
#   myspider/
#     settings.py
#     spiders/
#       quotes_spider.py

Creating a Spider

Subclass scrapy.Spider, set name and start_urls, then implement parse().

import scrapy

class QuotesSpider(scrapy.Spider):
    name = "quotes"
    start_urls = ["https://quotes.toscrape.com"]

    def parse(self, response):
        for quote in response.css("div.quote"):
            yield {
                "text": quote.css("span.text::text").get(),
                "author": quote.css("small.author::text").get(),
            }

All lessons in this course

  1. HTTP Requests with requests and httpx
  2. Parsing HTML with BeautifulSoup
  3. Building a Scrapy Spider
  4. Handling JavaScript and Anti-scraping Measures
← Back to Python Academy