如何使用加载的数据在ItemLoader中添加新值?

2024-05-11 13:43:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经开始了一个刮削项目,我有一个小问题ItemLoader

假设我在scraper中有一些ItemLoader

l = ScraperProductLoader(item=ScraperProduct(), selector=node)
l.add_xpath('sku', 'id/text()')

我想根据我提供的sku向项目加载器添加一个URL:

l.add_value('url', '?????')

……然而,基于the documentation,我看不到一个明确的方法来做到这一点

我考虑过的选择:

  • 输入处理器:添加一个字符串,并以某种方式传递sku作为上下文
  • 单独处理:不使用项目加载器创建URL

如何使用加载的数据在ItemLoader中添加新值


Tags: 项目textaddidnodeurlvaluescraper
1条回答
网友
1楼 · 发布于 2024-05-11 13:43:42

可以使用^{}方法:

get_output_value(field_name)

Return the collected values parsed using the output processor, for the given field. This method doesn’t populate or modify the item at all.

l.add_value('url', 'http://domain.com/' + l.get_output_value('scu'))

相关问题 更多 >