from scrapy.loader import ItemLoader from myproject.items import MyItem # Define the loader and add a value to it loader = ItemLoader(item=MyItem()) loader.add_value('name', 'John') # Access the loaded item item = loader.load_item() print(item['name']) # Output: 'John'
from scrapy.loader import ItemLoader from myproject.items import MyItem # Define the loader and add multiple values to it loader = ItemLoader(item=MyItem()) loader.add_value('name', 'John') loader.add_value('age', 30) # Access the loaded item item = loader.load_item() print(item['name']) # Output: 'John' print(item['age']) # Output: 30This example demonstrates how to load multiple values into an item using ItemLoader. The add_value method can be called multiple times to add additional values to the item. The ItemLoader class is part of the Scrapy package library, which provides a range of tools for web scraping, data extraction, and data processing.