本文整理汇总了Python中scrapy.loader.processors.TakeFirst方法的典型用法代码示例。如果您正苦于以下问题:Python processors.TakeFirst方法的具体用法?Python processors.TakeFirst怎么用?Python processors.TakeFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.loader.processors
的用法示例。
在下文中一共展示了processors.TakeFirst方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape_product
# 需要导入模块: from scrapy.loader import processors [as 别名]
# 或者: from scrapy.loader.processors import TakeFirst [as 别名]
def scrape_product(self, response):
item_loader = ItemLoader(item=MyItem(), response=response)
item_loader.default_input_processor = MapCompose(remove_tags)
item_loader.default_output_processor = TakeFirst()
item_loader.add_css("my_field", "selector")
return item_loader.load_item()
示例2: parse
# 需要导入模块: from scrapy.loader import processors [as 别名]
# 或者: from scrapy.loader.processors import TakeFirst [as 别名]
def parse(self, response):
item_loader = ItemLoader(item=MyItem(), response=response)
item_loader.default_input_processor = MapCompose(remove_tags)
item_loader.default_output_processor = TakeFirst()
#
#item_loader.add_css("my_field", "my_css")
#item_loader.add_xpath("my_field", "my_xpath")
#
return item_loader.load_item()
示例3: parse
# 需要导入模块: from scrapy.loader import processors [as 别名]
# 或者: from scrapy.loader.processors import TakeFirst [as 别名]
def parse(self, response):
item = PriceItem()
item_loader = ItemLoader(item=item, response=response)
item_loader.default_output_processor = TakeFirst()
item_loader.add_css("price", self.price_css)
item_loader.add_css("stock", self.stock_css)
item_loader.add_value("product_id", response.meta.get("product_id"))
item_loader.add_value("cron_id", self.cron_id)
item_loader.add_value("shop_id", self.shop_id)
item_loader.add_value("item_id", str(uuid.uuid1()))
item_loader.add_value("updated", str(datetime.datetime.now()))
item_loader.add_value("url", response.url)
return item_loader.load_item()
# 2. Updating database by calling the backend API
示例4: numeric_field
# 需要导入模块: from scrapy.loader import processors [as 别名]
# 或者: from scrapy.loader.processors import TakeFirst [as 别名]
def numeric_field():
return scrapy.Field(input_processor=MapCompose(DataUtils.remove_html), output_processor=TakeFirst())
示例5: price_field
# 需要导入模块: from scrapy.loader import processors [as 别名]
# 或者: from scrapy.loader.processors import TakeFirst [as 别名]
def price_field():
return scrapy.Field(input_processor=MapCompose(
lambda value: value.replace('$', '') if type(value) == str else value,
DataUtils.remove_html, float),
output_processor=TakeFirst())
示例6: date_field
# 需要导入模块: from scrapy.loader import processors [as 别名]
# 或者: from scrapy.loader.processors import TakeFirst [as 别名]
def date_field():
def parse_date(value):
date_format = value['date_format']
time_utils = TimeUtils(date_format=date_format)
date_obj = {**create_time_data(), **value}
start_timestamp, end_timestamp = time_utils.get_timestamps(date_obj)
return {
'start_timestamp': start_timestamp,
'end_timestamp': end_timestamp
}
return scrapy.Field(input_processor=MapCompose(DataUtils.remove_html, parse_date), output_processor=TakeFirst())
示例7: populate_item
# 需要导入模块: from scrapy.loader import processors [as 别名]
# 或者: from scrapy.loader.processors import TakeFirst [as 别名]
def populate_item(self, selector):
item_loader = ItemLoader(item=MySpiderItem(), selector=selector)
item_loader.default_input_processor = MapCompose(remove_tags)
item_loader.default_output_processor = TakeFirst()
#
#item_loader.add_css("my_field", "my_css")
#item_loader.add_xpath("my_field", "my_xpath")
#
return item_loader.load_item()