蜘蛛和python分布式爬虫的CrawlSpider存在着什么关系

  介绍

小编给大家分享一下蜘蛛和python分布式爬虫的CrawlSpider存在着什么关系,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!

CrawlSpider

深度爬虫,根据连接提取规则,会自动抓取页面中满足规则的连接,然后再请求解析,再抓取从而一直深入。

源码

“““   却;能够modules  implements 从而,CrawlSpider  which  is 从而recommended  spider 用使用   for  scraping  typical  web  sites  that  requires  crawling 页面。   ,   阅读/spiders.rst documentation 拷贝文档/主题   “““   ,   import 复制   import  6   ,   得到scrapy.http  import 请求,HtmlResponse   得到scrapy.utils.spider  import  iterate_spider_output   得到scrapy.spiders  import 蜘蛛   ,   ,   def 身份(x):   ,,,return  x   ,   ,   class 规则(对象):   ,   ,,,def  __init__(自我,,link_extractor,,回调=没有,cb_kwargs=没有,遵循=没有,process_links=没有,process_request=身份):   ,,,,,,,self.link_extractor =link_extractor   ,,,,,,,self.callback =回调   ,,,,,,,self.cb_kwargs =, cb_kwargs 一、{}   ,,,,,,,self.process_links =process_links   ,,,,,,,self.process_request =process_request   ,,,,,,,if  follow  is 没有:   ,,,,,,,,,,,self.follow =, False  if  callback  else 真实的   ,,,,,,,其他的:   ,,,,,,,,,,,self.follow =,   ,   ,   class  CrawlSpider(蜘蛛):   ,   ,,,rules =, ()   ,   ,,,def  __init__(自我,,*,,* *千瓦):   ,,,,,,,超级(CrawlSpider,,自我). __init__(*,, * *千瓦)   ,,,,,,,self._compile_rules ()   ,   ,,,def 解析(自我,,反应):   ,,,,,,,return  self._parse_response(反应,self.parse_start_url,, cb_kwargs={},遵循=True)   ,   ,,,def  parse_start_url(自我,,反应):   ,,,,,,,return  []   ,   ,,,def  process_results(自我,,反应,结果):   ,,,,,,,return 结果   ,   ,,,def  _build_request(自我,,规则,,链接):   ,,,,,,,r =,请求(url=link.url,回调=self._response_downloaded)   ,,,,,,,r.meta.update(=规则,规则,link_text=link.text)   ,,,,,,,return  r   ,   ,,,def  _requests_to_follow(自我,,反应):   ,,,,,,,if  not  isinstance(反应,HtmlResponse):   ,,,,,,,,,,,回来   ,,,,,,,seen =, ()   ,,,,,,,for  n, rule 拷贝列举(self._rules):   ,,,,,,,,,,,links =, [lnk  for  lnk 拷贝rule.link_extractor.extract_links(响应)   ,,,,,,,,,,,,,,,,,,,,if  lnk  not 看到拷贝)   ,,,,,,,,,,,if  links 以及rule.process_links:   ,,,,,,,,,,,,,,,links =, rule.process_links(链接)   ,,,,,,,,,,,for  link 拷贝链接:   ,,,,,,,,,,,,,,,seen.add(链接)   ,,,,,,,,,,,,,,,r =, self._build_request (n,链接)   ,,,,,,,,,,,,,,,油品收率rule.process_request(右)   ,   ,,,def  _response_downloaded(自我,,反应):   ,,,,,,,rule =, self._rules [response.meta[& # 39;规则# 39;]]   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

蜘蛛和python分布式爬虫的CrawlSpider存在着什么关系