Sync web-scraping-with-scrapy-and-mongodb with the updated tutorial - #835
Open
realpython-bot wants to merge 1 commit into
Open
realpython-bot wants to merge 1 commit into
realpython-bot wants to merge 1 commit into
Conversation
… of "Web Scraping With Scrapy and MongoDB" - Replace the spider's def start_requests(self) with async def start(self); Scrapy removed Spider.start_requests() in 2.16.0, so on current Scrapy the method was never called and the errback on the initial request was silently dropped. - Re-pin requirements.txt to the tutorial's new dependency set (Scrapy 2.18.0, pymongo 4.17.0, Python 3.14). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Syncs
web-scraping-with-scrapy-and-mongodb/with the maintenance update of the tutorial.What changed
books/books/spiders/book.py—def start_requests(self):→async def start(self):Scrapy deprecated
Spider.start_requests()in 2.13.0 and removed it in 2.16.0. On current Scrapy the method is never called, so the spider fell back to the defaultstart()and theerrback=self.log_errorthe tutorial wires onto the initial request was silently dropped. Confirmed on 2.18.0 with a scratch spider: an old-stylestart_requests()request comes back witherrback: None, while the newasync def start()yieldshttps://books.toscrape.com/witherrback: log_error, callback: parse.requirements.txt— re-pinned (==on every line) to match the tutorial's updateddependenciesfield:Scrapy==2.18.0,pymongo==4.17.0, resolved on Python 3.14. Transitive pins were regenerated from a clean resolve, sopyasn1,pyasn1_modules,setuptools, andsixdrop out of the tree andbrotlicomes in. Noconstraints.txtexists in this folder, so there was nothing to fold in.No other file in the folder needed a change:
items.py,pipelines.py,settings.py,tests/test_book.py,tests/sample.html,scrapy.cfg, andREADME.mdall already match the article's current code blocks. TheUSER_AGENT/DOWNLOADER_MIDDLEWARES/RETRY_*snippets the article refreshed this cycle are illustrative examples in the prose and are not part of the committedsettings.py.How this was verified
Everything below was actually run, in a fresh Python 3.14.6 venv installed from the new
requirements.txt:pip install -r requirements.txtresolves and installs cleanly on Python 3.14.scrapy version→Scrapy 2.18.0; the spider module imports cleanly.scrapy list→book.scrapy check→Ran 3 contracts ... OK(the@url/@returns items 20 20/@returns request 1 50/@scrapes url title pricecontracts, against the live Books to Scrape).python -m unittest discover→Ran 3 tests ... OK.mongod --dbpath /tmp/mongodata,127.0.0.1:27017) in the CI VM, since the distro has nomongodb-serverpackage.scrapy crawl bookcompleted against the live site andbooks_db.booksheld 1000 documents, each with the SHA-256_id,url,title, andprice— e.g.A Light in the Attic / £51.77. A secondscrapy crawl booklogged exactly 1000Dropped: Duplicate item foundwarnings tobook_scraper.log, so the dedup path inMongoPipeline.process_item()behaves as the tutorial describes.ruff==0.14.1from the rootrequirements.txt:uvx ruff@0.14.1 format --check web-scraping-with-scrapy-and-mongodb→9 files already formatted;uvx ruff@0.14.1 check web-scraping-with-scrapy-and-mongodb→All checks passed!.What was NOT verified / noted for a human
mongod --versionandmongoshsample output still show MongoDB 7.0.12 (a known LOW finding left for a human on the card). I ran 8.0.4 here, and I did not installmongosh, so the article's sample output blocks are still unrefreshed. Nothing in this PR depends on that.ScrapyDeprecationWarnings:MongoPipeline.open_spider(),.close_spider(), and.process_item()"requires a spider argument, this is deprecated and the argument will not be passed in future Scrapy versions." The tutorial's own code blocks still use the(self, item, spider)signatures, so I did not change the pipeline here — the repo must match the published article. This is worth filing as adeprecated-apifinding on the next research pass so the article and this folder can move together.Needs a human merge.
🤖 Generated with Claude Code