午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

Python Scrapy框架:通用爬蟲之CrawlSpider用法簡單示例

瀏覽:43日期:2022-07-30 13:12:21

本文實(shí)例講述了Python Scrapy框架:通用爬蟲之CrawlSpider用法。分享給大家供大家參考,具體如下:

步驟01: 創(chuàng)建爬蟲項(xiàng)目

scrapy startproject quotes

步驟02: 創(chuàng)建爬蟲模版

scrapy genspider -t quotes quotes.toscrape.com

步驟03: 配置爬蟲文件quotes.py

import scrapyfrom scrapy.spiders import CrawlSpider, Rulefrom scrapy.linkextractors import LinkExtractorclass Quotes(CrawlSpider): # 爬蟲名稱 name = 'get_quotes' allow_domain = [’quotes.toscrape.com’] start_urls = [’http://quotes.toscrape.com/’]# 設(shè)定規(guī)則 rules = ( # 對(duì)于quotes內(nèi)容頁URL,調(diào)用parse_quotes處理, # 并以此規(guī)則跟進(jìn)獲取的鏈接 Rule(LinkExtractor(allow=r’/page/d+’), callback=’parse_quotes’, follow=True), # 對(duì)于author內(nèi)容頁URL,調(diào)用parse_author處理,提取數(shù)據(jù) Rule(LinkExtractor(allow=r’/author/w+’), callback=’parse_author’) )# 提取內(nèi)容頁數(shù)據(jù)方法 def parse_quotes(self, response): for quote in response.css('.quote'): yield {’content’: quote.css(’.text::text’).extract_first(), ’author’: quote.css(’.author::text’).extract_first(), ’tags’: quote.css(’.tag::text’).extract() } # 獲取作者數(shù)據(jù)方法 def parse_author(self, response): name = response.css(’.author-title::text’).extract_first() author_born_date = response.css(’.author-born-date::text’).extract_first() author_bron_location = response.css(’.author-born-location::text’).extract_first() author_description = response.css(’.author-description::text’).extract_first() return ({’name’: name, ’author_bron_date’: author_born_date, ’author_bron_location’: author_bron_location, ’author_description’: author_description })

步驟04: 運(yùn)行爬蟲

scrapy crawl quotes

更多相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python正則表達(dá)式用法總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》

希望本文所述對(duì)大家基于Scrapy框架的Python程序設(shè)計(jì)有所幫助。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲系列在线观看 | www.成人免费 | 午夜激情免费视频 | 国产精品一区二区免费看 | 一级片黑人 | 成人毛片一区二区三区 | 一级免费片| 久久久久国产视频 | 香蕉视频免费在线看 | 成人国产免费 | 91视频免费在线看 | 久久久久久久免费 | 手机超碰 | 亚洲伊人影院 | 美女av在线免费观看 | 五月婷丁香 | 国产精品波多野结衣 | 久久久精品一区二区 | 日本道中文字幕 | 伊人毛片 | 亚洲精品视频在线播放 | 成人欧美一区 | 黄色v片 | 成人国产免费 | 艹久久| 热99视频 | 亚洲欧美日韩第一页 | 6699嫩草久久久精品影院 | 国产无套丰满白嫩对白 | 欧美黑人性猛交xxx 国产婷婷一区二区 | 国产成人一区二区在线观看 | 最近日韩免费视频 | 黄色小视频免费观看 | www.久久| 国产日产亚洲精品 | 亚洲日日日 | 欧美有码视频 | 国产午夜精品久久久久久久 | 国产一区不卡 | 九九热在线视频 | 成人高清视频在线观看 |