crawl spider

Posted airapple

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了crawl spider相关的知识,希望对你有一定的参考价值。

crawlspider

使用
scrapy genspider -t crawl 文件名字 网址


crawlspider是什么?
也是一个spider,是Spider的一个子类,所以其功能要比Spider要强大
多的一个功能是:提取链接的功能,根据一定的规则,提取指定的链接


链接提取器
LinkExtractor(
allow=xxx, # 正则表达式,要(*)
deny=xxx, # 正则表达式,不要这个
restrict_xpaths=xxx, # xpath路径(*)
restrict_css=xxx, # 选择器(*)
deny_domains=xxx, # 不允许的域名
)

通过正则提取链接
links = LinkExtractor(allow=r‘/movie/?page=d‘)
将所有包含这个正则表达式的href全部获取到返回
links.extract_links(response)进行查看提取到的链接
【注】将重复的url去除掉
通过xpath提取
links = LinkExtractor(restrict_xpaths=‘//ul[@class="pagination pagination-sm"]/li/a‘)
通过css提取
links = LinkExtractor(restrict_css=‘.pagination > li > a‘)

 























以上是关于crawl spider的主要内容,如果未能解决你的问题,请参考以下文章

web crawling(plus5) news crawling and proxy

crawl spider

Python Scrapy:“runspider”和“crawl”命令有啥区别?

Scrapy process.crawl() 将数据导出到 json

web crawling

Crawlings