将Scrapy数据添加到不带标题行的csv

发布于 2025-01-16 10:08:26 字数 458 浏览 5 评论 0原文

我们有一个本地网站,可以跟踪使用特定许可证的人数。我创建了一个刮刀,每小时运行一次。我遇到的唯一问题是创建如下所示的数据。

active_users,date,time
35,22/03/2022,11:38:30.397745
active_users,date,time
36,22/03/2022,11:44:04.753589

我发现的问题是,每次运行 scrapy scrapy users 时,它都会添加该标头。我知道 scrapy 有 CsvItemExporter() 可以删除标头,但我不太确定如何使用它。

我只需要输出 csv 看起来像

active_users,date,time
35,22/03/2022,11:38:30.397745
36,22/03/2022,11:44:04.753589

We have a local website that tracks the number of people using a certain license. I have create a scraper with that should run every hour. The only issue I have it's creating data that looks like this.

active_users,date,time
35,22/03/2022,11:38:30.397745
active_users,date,time
36,22/03/2022,11:44:04.753589

the issue I find is that every time scrapy crawl users is ran it adds that header. I know scrapy has CsvItemExporter() that can remove the header but I'm not too sure how to use it.

I just need the output csv to look like

active_users,date,time
35,22/03/2022,11:38:30.397745
36,22/03/2022,11:44:04.753589

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看春风乍起 2025-01-23 10:08:27

如果您使用 scrapy 2.4 及更高版本,您可以在定义 FEED 时直接更改此设置,如下所示。

custom_settings = {"FEEDS": { "items.csv": {"format": "csv", "item_export_kwargs": {"include_headers_line": False}}}}

这将附加到文件的内容,而不是每次添加新的标头。

If you are using scrapy version 2.4 and above you can directly change this setting when defining the FEED such as below.

custom_settings = {"FEEDS": { "items.csv": {"format": "csv", "item_export_kwargs": {"include_headers_line": False}}}}

This will append to the contents of the file instead of adding a new header each time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文