随笔 - 31  文章 - 0  评论 - 0  阅读 - 2430

随笔分类 -  04-数据存储篇

<4> pipeline
摘要:"""scrapy 保存管道数据""" from scrapy.exporters import CsvItemExporter class CsvPipeline: def __init__(self): # 文件存储初始化操作 self.file = open('filename.csv', ' 阅读全文
posted @ 2022-11-02 16:30 不是霉蛋 阅读(37) 评论(0) 推荐(0) 编辑
<3> MongoDB存储
摘要:from pymongo import MongoClient class Spider(object): def __init__(self): # 将数据存储到数据库中 try: self.client = MongoClient('localhost', 27017) self.sina_db 阅读全文
posted @ 2022-11-02 16:20 不是霉蛋 阅读(18) 评论(0) 推荐(0) 编辑
<2> MySQL存储
摘要:import mysql.connector """数据模型类""" class QingHuaModel(object): def __init__(self, title, time, contents): self.title = title self.time = time self.con 阅读全文
posted @ 2022-11-02 16:14 不是霉蛋 阅读(18) 评论(0) 推荐(0) 编辑
<1> csv 存储
摘要:"""方式一(scrapy下):""" scrapy crawl 爬虫名 -o 保存的csv文件名 """方式二(常用):""" from scrapy.exporters import CsvItemExporter class CsvPipeline: def __init__(self): # 阅读全文
posted @ 2022-11-02 16:08 不是霉蛋 阅读(30) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示