2.0 新版功能. 刮痧 partial support 对于 coroutine syntax . 支持的可调用项¶以下可调用项可以定义为使用
使用¶Scrapy中有几个协同程序的用例。在为以前的垃圾版本(如下载程序中间件和信号处理程序)编写时,会返回延迟的代码可以重写为更简短、更干净: from itemadapter import ItemAdapter
class DbPipeline:
def _update_item(self, data, item):
adapter = ItemAdapter(item)
adapter['field'] = data
return item
def process_item(self, item, spider):
adapter = ItemAdapter(item)
dfd = db.get_some_data(adapter['id'])
dfd.addCallback(self._update_item, item)
return dfd
变成:: from itemadapter import ItemAdapter
class DbPipeline:
async def process_item(self, item, spider):
adapter = ItemAdapter(item)
adapter['field'] = await db.get_some_data(adapter['id'])
return item |
Archiver|手机版|笨鸟自学网 ( 粤ICP备20019910号 )
GMT+8, 2025-8-30 17:45 , Processed in 0.022547 second(s), 19 queries .
Powered by Discuz! X3.5
© 2001-2017 Discuz Team. Template By 【未来科技】【 www.wekei.cn 】