scrapy數(shù)據(jù)采集學(xué)習(xí)

創(chuàng)建虛擬環(huán)境

1.png

在這里,直接使用pip install scrapy,結(jié)果報錯,如下圖所示:
報錯1.png

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

創(chuàng)建采集項目
scrapy startproject quotes
定義spider
這里下載python編輯器pycharm,與云服務(wù)器聯(lián)結(jié),創(chuàng)建quotes_spider.py

quotes_spider.png

quotes_spider1.png

這里直接展示可以翻頁抓取的代碼
執(zhí)行爬蟲
scrapy crawl quotes

執(zhí)行爬蟲1.png

執(zhí)行爬蟲2.png

存儲數(shù)據(jù)
scrapy crawl quotes -o quotes1.json ,得到quotes1.json文件:

quotes1json.png

最后將其轉(zhuǎn)化為xml文件

quotesxml.png

同理采集作者信息
創(chuàng)建authors_spider.py,再執(zhí)行爬蟲scrapy crawl authors,并存儲數(shù)據(jù)scrapy crawl quotes -o author.json ,得到author.json文件,最后轉(zhuǎn)成xml文件。

authors_spider1.png
authors_spider.png
authorsjson.png
authorxml.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容