【发布时间】:2019-03-13 20:26:26
【问题描述】:
我正在将 Scrapy 项目密钥从 items.py 导入到 pipelines.py。
问题是导入项目的顺序与items.py文件中定义的不同。
我的items.py 文件:
class NewAdsItem(Item):
AdId = Field()
DateR = Field()
AdURL = Field()
在我的pipelines.py:
from adbot.items import NewAdsItem
...
def open_spider(self, spider):
self.ikeys = NewAdsItem.fields.keys()
print("Keys in pipelines: \t%s" % ",".join(self.ikeys) )
#self.createDbTable(ikeys)
输出是:
Keys in pipelines: AdId,AdURL,DateR
而不是预期的:AdId,DateR,AdURL。
如何确保导入的订单保持不变?
注意:这可能与How to get order of fields in Scrapy item 有关,但根本不清楚发生了什么,因为Python3 文档声明列表和字典应该保留它们的顺序。另请注意,当使用process_item() 和item.keys() 时,将保留顺序!但我需要访问 keys 以便 before item 被刮掉。
【问题讨论】:
标签: python python-3.x scrapy scrapy-pipeline