創(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