How baabaaox/scrapydouban works
Main Components Identification
• Scrapy (Douban crawler) Service – This is the core of the system. It contains the spiders which are responsible for scraping subject IDs, metadata, and comments. Within the “scrapy/douban” folder, you have modules for setting up items, pipelines, settings, and various spiders.
• Docker-based Containers – There are three containers per the README:
• douban_scrapyd: Runs the Python 3.9 environment with Scrapy, Scrapyd (a service to deploy and schedule crawls), and additional libraries. It exposes port 6800 for the Scrapyd interface.
• douban_db: A MySQL 8 container that stores the scraped data. Its database is initialized with an SQL dump located in “docker/mysql/douban.sql.”
• douban_adminer: Runs Adminer on port 8080 for easy database administration.
• Data Storage – The image downloads are saved in a specific directory (in the scrapyd container at “/srv/ScrapyDouban/storage”) as handled by the pipeline.
• Proxy IP Support – Although not enabled by default, there’s a middleware defined (ProxyMiddleware) hinting at support for proxy IPs to overcome anti-crawling mechanisms.
Component Relationships and Data Flow
• The User/Developer interacts through the Docker Compose interface. When containers are started, the Scrapy project (deployed on the douban_scrapyd container) connects to the MySQL container (douban_db) to persist metadata and comments.
• The spiders execute in the Scrapy service, process and download images via the pipeline (CoverPipeline), and store results in the MySQL database.
• The Adminer container (douban_adminer) provides an external UI to query and manage the MySQL data.
• Optionally, if using the scrapyd-client, the project can be deployed remotely on the douban_scrapyd container for scheduling tasks.
Architectural Patterns and Design Principles
• Containerization: Docker isolates each service (the crawler, database, admin interface) for modularity and ease of deployment.
• Separation of Concerns: The Scrapy layer is strictly responsible for crawling, processing, and storing data, while persistence is centralized in the MySQL container.
• Pipeline-based Processing: The Scrapy project uses pipelines to process items (e.g., image downloads and data validation), emphasizing a decoupled data processing design.
a. Components:
• Douban_Scrapyd Container: Inside, show sub-components like:
• Spiders: movie_subject, movie_meta, movie_comment, book_subject, book_meta, book_comment.
• Pipelines: CoverPipeline for image downloads.
• Settings & Middlewares: ProxyMiddleware (optional proxy) and other configuration files.
• MySQL Database Container (douban_db): Mark that it’s initialized with “douban.sql” and stores scraped data.
• Adminer Container (douban_adminer): Use as a UI for database management.
b. Relationships:
c. Technology Stack Labels:
• Python3, Scrapy, Scrapyd (in douban_scrapyd).
• MySQL 8 for persistence.
• Docker as the orchestration technology.
• Adminer for database management.
d. Interaction Flow:
• Typical flow: Crawling (subject collection → metadata capture → comments fetching) with subsequent pipeline processing (image download) and then data storage in MySQL.