I've a list of tuples in the form (id,url) I need to crawl a product from a list of urls, and when those products are crawled i need to store them in database under their id.
problem is i can't understand how to pass id to parse function so that i can store crawled item under their id.
Initialize start urls in start_requests()
and pass id
in meta
:
class MySpider(Spider):
mapping = [(1, 'my_url1'), (2, 'my_url2')]
...
def start_requests(self):
for id, url in self.mapping:
yield Request(url, callback=self.parse_page, meta={'id': id})
def parse_page(self, response):
id = response.meta['id']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With