mirror of
https://github.com/NohamR/phpBB-forum-scraper.git
synced 2026-02-21 18:15:43 +00:00
Fork and refactor project for scraping macserialjunkie.com: add a new phpBB spider (uses python-dotenv for credentials, form login enabled, multiple start_urls, robust ID/time/text extraction and pagination) and an SQLitePipeline that saves posts to posts.db with a tqdm progress bar. Update settings to use the SQLite pipeline, increase concurrency, reduce download delay, disable robots.txt, set JOBDIR for resume and silence logs; add .env.example and .python-version, update README and requirements (add tqdm), tidy .gitignore, and add pyproject.toml. Also reorganize package layout (rename/move phpBB_scraper modules), remove legacy pipeline and old spider implementations, and add a dependency lock file (uv.lock).
57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
||
|
||
# Define here the models for your spider middleware
|
||
#
|
||
# See documentation in:
|
||
# http://doc.scrapy.org/en/latest/topics/spider-middleware.html
|
||
|
||
from scrapy import signals
|
||
|
||
|
||
class PhpbbScraperSpiderMiddleware(object):
|
||
# Not all methods need to be defined. If a method is not defined,
|
||
# scrapy acts as if the spider middleware does not modify the
|
||
# passed objects.
|
||
|
||
@classmethod
|
||
def from_crawler(cls, crawler):
|
||
# This method is used by Scrapy to create your spiders.
|
||
s = cls()
|
||
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
|
||
return s
|
||
|
||
def process_spider_input(self, response, spider):
|
||
# Called for each response that goes through the spider
|
||
# middleware and into the spider.
|
||
|
||
# Should return None or raise an exception.
|
||
return None
|
||
|
||
def process_spider_output(self, response, result, spider):
|
||
# Called with the results returned from the Spider, after
|
||
# it has processed the response.
|
||
|
||
# Must return an iterable of Request, dict or Item objects.
|
||
for i in result:
|
||
yield i
|
||
|
||
def process_spider_exception(self, response, exception, spider):
|
||
# Called when a spider or process_spider_input() method
|
||
# (from other spider middleware) raises an exception.
|
||
|
||
# Should return either None or an iterable of Response, dict
|
||
# or Item objects.
|
||
pass
|
||
|
||
def process_start_requests(self, start_requests, spider):
|
||
# Called with the start requests of the spider, and works
|
||
# similarly to the process_spider_output() method, except
|
||
# that it doesn’t have a response associated.
|
||
|
||
# Must return only requests (not items).
|
||
for r in start_requests:
|
||
yield r
|
||
|
||
def spider_opened(self, spider):
|
||
spider.logger.info("Spider opened: %s" % spider.name)
|