知识卡片
导出格式和存储后端可以独立替换
FeedExporter一边调用ItemExporter序列化Item,一边调用FeedStorage写入目的地,FEED_EXPORTERS和FEED_STORAGES分别管理它们。因而从S3的XML改成标准输出的其他编码,涉及两种选择而非重写抓取。图8.4给出基类/接口角色和具体例,接口签名以目标版本为准,本次未生成或上传任何Feed。
结构图: 类图
classDiagram
class FeedExporter
class BaseItemExporter {
+start_exporting()
+export_item(item)
+finish_exporting()
}
class JsonItemExporter
class JsonLinesItemExporter
class XmlItemExporter
class IFeedStorage {
+open()
+store()
}
class FileFeedStorage
class StdoutFeedStorage
class BlockingFeedStorage
class S3FeedStorage
class FTPFeedStorage
FeedExporter ..> BaseItemExporter : 序列化
FeedExporter ..> IFeedStorage : 保存
BaseItemExporter <|-- JsonItemExporter
BaseItemExporter <|-- JsonLinesItemExporter
BaseItemExporter <|-- XmlItemExporter
IFeedStorage <|.. FileFeedStorage
IFeedStorage <|.. StdoutFeedStorage
IFeedStorage <|.. BlockingFeedStorage
BlockingFeedStorage <|-- S3FeedStorage
BlockingFeedStorage <|-- FTPFeedStorage
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第8章 Scrapy编程 8.6 中间件延伸 · 查看原书依据
FEED_STORAGES 和FEED_EXPORTERS
参考来源
- 位置:《Python编程精进(第1辑)(套装共3册)(异步图书)》精通Python爬虫框架Scrapy · 第8章 Scrapy编程,spine040单元010;来源项目book-sources,extracted/Python编程精进(第1辑)(套装共3册)(异步图书)/_epub-src/OEBPS/text00039.html。
- 结论依据:原文FeedExporter分别调用ItemExporter与FeedStorage,直接支持编码与目的地分开选择,不必为换后端重写抓取逻辑。补充核验入口:https://docs.scrapy.org/en/latest/topics/feed-exports.html。未在本机运行示例或改变环境。
- 原始内容:ckle编码输出。这两个结构还可以使用 FEED_STORAGES 和 FEED_EXPORTERS 设置进行独立扩展。最后, scrapy check 命令使用的contract也有其自身的结构,可以使用 SPIDER_CONTRACTS 设置进行扩展。