Cycle in Scrapy ItemLoader
Cycle in Scrapy ItemLoader
https://doc.scrapy.org/en/latest/topics/loaders.html#using-item-loaders-to-populate-items
from scrapy.loader import ItemLoader
from myproject.items import Product
def parse(self, response):
l = ItemLoader(item=Product(), response=response)
l.add_xpath('name', '//div[@class="product_name"]')
l.add_xpath('name', '//div[@class="product_title"]')
l.add_xpath('price', '//p[@id="price"]')
l.add_css('stock', 'p#stock]')
l.add_value('last_updated', 'today') # you can also use literal values
return l.load_item()
But if I get from webpage 2 names, prices, etc, how to add it to l.load_item()
?
l.load_item()
Because I added the cycle but if in the end, I write return
cycle will work only once.
How to right to do it?
return
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.