scrapy数据采集学习

创建虚拟环境

1.png

在这里,直接使用pip install scrapy,结果报错,如下图所示:
报错1.png

因此安装twisted和cryptography,最后 pip install scrapy 安装scrapy,安装成功,如下图:
anzhuang.png

创建采集项目
scrapy startproject quotes
定义spider
这里下载python编辑器pycharm,与云服务器联结,创建quotes_spider.py

quotes_spider.png

quotes_spider1.png

这里直接展示可以翻页抓取的代码
执行爬虫
scrapy crawl quotes

执行爬虫1.png

执行爬虫2.png

存储数据
scrapy crawl quotes -o quotes1.json ,得到quotes1.json文件:

quotes1json.png

最后将其转化为xml文件

quotesxml.png

同理采集作者信息
创建authors_spider.py,再执行爬虫scrapy crawl authors,并存储数据scrapy crawl quotes -o author.json ,得到author.json文件,最后转成xml文件。

authors_spider1.png
authors_spider.png
authorsjson.png
authorxml.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容