from scrapy.loader import ItemLoader from myproject.items import ImageItem loader = ItemLoader(item=ImageItem(), response=response) loader.add_xpath('image_url', '//img/@src') image_item = loader.load_item() image_url = loader.get_output_value('image_url')
from scrapy.loader import ItemLoader from myproject.items import ArticleItem loader = ItemLoader(item=ArticleItem(), response=response) loader.add_xpath('title', '//h1/text()') loader.add_xpath('author', '//span[@class="author"]/text()') loader.add_xpath('body', '//div[@class="article-body"]/text()') article_item = loader.load_item() title, author, body = [loader.get_output_value(field) for field in ['title', 'author', 'body']]In this example, the XPath expressions are used to extract the title, author, and body text of an article. The get_output_value method is used to retrieve the values from the loader object. The Scrapy library is used to import the ItemLoader class and load data from websites easily.