I am writing a scrapy spider that takes as input many urls and classifies them into categories (returned as items). These URLs are fed to the spider via my crawler's start_requests()
method.
Some URLs can be classified without downloading them, so I would like to yield
directly an Item
for them in start_requests()
, which is forbidden by scrapy. How can I circumvent this?
I have thought about catching these requests in a custom middleware that would turn them into spurious Response
objects, that I could then convert into Item
objects in the request callback, but any cleaner solution would be welcome.
I think using a spider middleware and overwriting the start_requests() would be a good start.
In your middleware, you should loop over all urls in start_urls, and could use conditional statements to deal with different types of urls.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments