How kenser/pornhubbot works
Purpose and Entry Point
This is a Python 2.7 Scrapy crawler for collecting PornHub video metadata: title, source-page URL, thumbnail URL, duration, and 480p MP4 URL. It persists results to MongoDB. Runtime starts through PornHub/quickstart.py, with Scrapy project configuration in PornHub/scrapy.cfg.
Crawl Orchestration
The primary spider initiates concurrent requests across several PornHub categories, follows paginated listing pages, and schedules discovered video detail pages. The crawl logic is centered in PornHub/PornHub/spiders/pornHubSpider.py; project-level crawler behavior is configured by PornHub/PornHub/settings.py.
Request Identity and Access Boundary
Requests receive randomized cookie and User-Agent identity data to vary outbound traffic characteristics. User-Agent inventory resides in PornHub/PornHub/user_agents.py; request/response interception and header assignment are expected through PornHub/PornHub/middlewares.py. This is the boundary between Scrapy’s scheduler/downloader and the external PornHub site.
Extraction and Domain Model
The spider converts listing/detail-page HTML into structured crawl records containing the fields described in the README. The Scrapy item schema is defined in PornHub/PornHub/items.py, while PornHub-specific classification or record types are separated in PornHub/PornHub/pornhub_type.py.
Processing and Persistence
Scrapy emits extracted items through its pipeline stage. PornHub/PornHub/pipelines.py is the persistence boundary and is responsible for writing results to MongoDB, including the PhRes collection/table described by the project. MongoDB is the material external dependency and must be installed and running before execution.
Runtime Composition
PornHub/quickstart.py launches the crawler; PornHub/PornHub/settings.py controls concurrency, delays, pipelines, middleware, and related Scrapy runtime behavior. The package root PornHub/PornHub/__init__.py establishes the importable Scrapy project, and PornHub/PornHub/spiders/__init__.py registers the spider package.
Primary Flow
Startup script → Scrapy engine/settings → spider category requests → downloader middleware applies request identity → category and pagination parsing → video detail extraction → item creation → pipeline → MongoDB PhRes storage. The system’s throughput is primarily governed by Scrapy concurrency/network settings and MongoDB write capacity.
Main entry points: pornHubSpider.py PornHub spider · settings.py Scrapy settings · middlewares.py Downloader middleware · pipelines.py Mongo pipeline
Components 15
Scrapy Runtime
- Crawler launcher · Starts the Scrapy crawler.
PornHub/quickstart.py - Scrapy settings · Configures concurrency, middleware, and pipelines.
PornHub/PornHub/settings.py - Project package
PornHub/PornHub/__init__.py - Scrapy engine · Schedules requests and routes responses and items.
Crawl & Extraction
- Spider package
PornHub/PornHub/spiders/__init__.py - PornHub spider · Requests categories and pagination, then schedules video detail pages.
PornHub/PornHub/spiders/pornHubSpider.py - Category & listing pages · Provide video links and pagination.
- Video detail pages · Provide video metadata and the 480p MP4 URL.
- Video item schema · Defines title, source URL, thumbnail, duration, and MP4 fields.
PornHub/PornHub/items.py - PornHub record types
PornHub/PornHub/pornhub_type.py
Request Access Boundary
- Downloader middleware · Intercepts requests and assigns headers.
PornHub/PornHub/middlewares.py - User-Agent inventory · Supplies randomized User-Agent values.
PornHub/PornHub/user_agents.py - PornHub site
Persistence
- Mongo pipeline · Writes extracted records to the PhRes collection.
PornHub/PornHub/pipelines.py - MongoDB PhRes · Persistent crawl-result storage.
Connections 20
- Crawler launcher → Scrapy engine: launches
- Crawler launcher → Scrapy settings: loads
- Scrapy settings → Scrapy engine: configures
- Project package → Scrapy engine: provides project
- Spider package → PornHub spider: contains
- Scrapy engine → PornHub spider: runs
- PornHub spider → Category & listing pages: requests categories and pages
- Category & listing pages → PornHub spider: video links and pagination
- PornHub spider → Video detail pages: schedules video pages
- Video detail pages → PornHub spider: video metadata HTML
- Scrapy engine → Downloader middleware: outbound requests
- Downloader middleware → User-Agent inventory: selects identity
- Downloader middleware → PornHub site: applies headers and cookies
- PornHub site → Category & listing pages: serves
- PornHub site → Video detail pages: serves
- PornHub spider → Video item schema: creates items
- PornHub spider → PornHub record types: uses
- Video item schema → Mongo pipeline: emits items
- Scrapy settings → Mongo pipeline: enables
- Mongo pipeline → MongoDB PhRes: writes PhRes records