python scrapy 需要帮助。我想保存到 (.csv) 文件。我该怎么做?
我正在使用 debian Bullseye (11.2) 我想保存到 (.csv) 文件。 我该怎么做?
from scrapy.spiders import CSVFeedSpider
class CsSpiderSpider(CSVFeedSpider):
name = 'cs_spider'
allowed_domains = ['ocw.mit.edu/courses/electrical-engineering-and-computer-science/']
start_urls = ['http://ocw.mit.edu/courses/electrical-engineering-and-computer-science//feed.csv']
# headers = ['id', 'name', 'description', 'image_link']
# delimiter = '\t'
# Do any adaptations you need here
#def adapt_response(self, response):
# return response
def parse_row(self, response, row):
i = {}
#i['url'] = row['url']
#i['name'] = row['name']
#i['description'] = row['description']
return i
I'm using debian Bullseye (11.2)
I want to save to a (.csv) file.
How can I do this?
from scrapy.spiders import CSVFeedSpider
class CsSpiderSpider(CSVFeedSpider):
name = 'cs_spider'
allowed_domains = ['ocw.mit.edu/courses/electrical-engineering-and-computer-science/']
start_urls = ['http://ocw.mit.edu/courses/electrical-engineering-and-computer-science//feed.csv']
# headers = ['id', 'name', 'description', 'image_link']
# delimiter = '\t'
# Do any adaptations you need here
#def adapt_response(self, response):
# return response
def parse_row(self, response, row):
i = {}
#i['url'] = row['url']
#i['name'] = row['name']
#i['description'] = row['description']
return i
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是使用 scrapy 导出的
FEEDS
的示例。将文件的输出保存为
.csv
格式。此外,要指定要导出的列及其顺序,请使用FEED_EXPORT_FIELDS
。您可以在 中阅读有关此内容的更多信息docs在命令行中,您可以运行:
但是,在命令行中运行上述内容时,请确保注释掉
process
及以下的所有代码。Here's an example of using the
FEEDS
export from scrapy.Will save the output of your file into
.csv
format. Furthermore, To specify columns to export and their order useFEED_EXPORT_FIELDS
. You can read more about this in the docsIn the command line you can run:
However, when running the above in the command line make sure to comment out all the code from
process
and below.