這篇文章主要介紹python分布式爬蟲中的Redis如何使用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
利用redis做分布式系統(tǒng),最經(jīng)典的就是scrapy-Redis,這是比較成熟的框架。同時(shí)我們也可以利用Redis的隊(duì)列功能或者訂閱發(fā)布功能來打造自己的分布式系統(tǒng)。
Redis作為通信載體的優(yōu)點(diǎn)是讀寫迅速,對爬蟲的速度影響可忽略不計(jì),使用比較普遍。
主程序示例:
import scrapy from scrapy.http import Request from scrapy.selector import HtmlXPathSelector from scrapy.dupefilter import RFPDupeFilter from scrapy.core.scheduler import Scheduler import redis from ..items import XiaobaiItem from scrapy_redis.spiders import RedisSpider class RenjianSpider(RedisSpider): name = 'baidu' allowed_domains = ['baidu.com'] def parse(self, response): news_list = response.xpath('//*[@id="content-list"]/div[@class="item"]') for news in news_list: content = response.xpath('.//div[@class="part1"]/a/text()').extract_first().strip() url = response.xpath('.//div[@class="part1"]/a/@href').extract_first() yield XiaobaiItem(url=url,content=content) yield Request(url='http://dig..com/',callback=self.parse)
以上是“python分布式爬蟲中的Redis如何使用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前標(biāo)題:python分布式爬蟲中的Redis如何使用-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://jinyejixie.com/article16/digidg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、定制開發(fā)、微信小程序、ChatGPT、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容