SCP05: lambda callback
What it does
Why is this bad?
While lambdas can work as request callbacks, they will become an issue if you
ever start using JOBDIR, since lambdas are not serializable.
Example
import scrapy
class MySpider(scrapy.Spider):
name = "myspider"
def start(self):
yield scrapy.Request(
url="https://toscrape.com",
callback=lambda response: {"title": response.css("h1::text").get()},
)
Use instead:
import scrapy
class MySpider(scrapy.Spider):
name = "myspider"
def start(self):
yield scrapy.Request(
url="https://toscrape.com",
callback=self.my_callback,
)
def my_callback(self, response):
yield {"title": response.css("h1::text").get()}