You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scrapy Feeds无法存储数据求助:已爬取数据但无法保存至S3或本地

Scrapy爬取数据后无法导出至S3或本地JSON文件

我用Scrapy爬虫成功爬取了4156条数据,但尝试将数据存储到S3时,无论怎么配置都无法完成导出;保存到本地JSON文件同样失败。

日志信息:

2024-02-20 00:08:39 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 2338579,
 'downloader/request_count': 4507,
 'downloader/request_method_count/GET': 4507,
 'downloader/response_bytes': 22670523,
 'downloader/response_count': 4507,
 'downloader/response_status_count/200': 4507,
 'dupefilter/filtered': 12,
 'elapsed_time_seconds': 206.962822,
 'finish_reason': 'No data in response',
 'finish_time': datetime.datetime(2024, 2, 20, 0, 8, 39, 297006, tzinfo=datetime.timezone.utc),
 'httpcompression/response_bytes': 1780,
 'httpcompression/response_count': 2,
 'item_scraped_count': 4156,
 'log_count/DEBUG': 8667,
 'log_count/INFO': 14,
 'memusage/max': 100188160,
 'memusage/startup': 91996160,
 'request_depth_max': 349,
 'response_received_count': 4507,
 'robotstxt/request_count': 1,
 'robotstxt/response_count': 1,
 'robotstxt/response_status_count/200': 1,
 'scheduler/dequeued': 4506,
 'scheduler/dequeued/memory': 4506,
 'scheduler/enqueued': 4506,
 'scheduler/enqueued/memory': 4506,
 'start_time': datetime.datetime(2024, 2, 20, 0, 5, 12, 334184, tzinfo=datetime.timezone.utc)}
2024-02-20 00:08:39 [scrapy.core.engine] INFO: Spider closed (No data in response)

我尝试了多种数据保存配置,但均未成功:

  • 方案1:在start_requests的custom_settings中配置FEEDS导出至S3
storage_full_path: str = f"s3://mybucket/{execution_datetime.strftime('%Y/%m/%d/%H/%M/%S')}/{crawler_storage_name}.json"
self.custom_settings["FEEDS"] = {
            storage_full_path: {
                "format": "json",
                "encoding": "utf8",
                "store_empty": False,
                "indent": 4,
            }
        }
  • 方案2:在settings.py中配置FEEDS保存至本地文件
FEEDS = {
    "output.json": {
        "format": "json",
        "encoding": "utf8",
        "indent": 4,
    }
}
  • 方案3:在start_requests的custom_settings中用URI配置FEEDS保存至本地文件
self.custom_settings["FEEDS"] = {
            "file:///tmp/output.json": {
                "format": "json",
                "encoding": "utf8",
                "indent": 4,
            }
        }
  • 方案4:在start_requests的custom_settings中配置FEEDS保存至本地文件
self.custom_settings["FEEDS"] = {
            "output.json": {
                "format": "json",
                "encoding": "utf8",
                "indent": 4,
            }
        }

内容的提问来源于stack exchange,提问作者GBonc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 10:52:33