028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

爬虫CrawlSpider模板的用法

本篇内容介绍了“爬虫Crawl Spider模板的用法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

成都创新互联-专业网站定制、快速模板网站建设、高性价比长顺网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式长顺网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖长顺地区。费用合理售后完善,十年实体公司更值得信赖。

1.Spider模板

import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
class CsDNSpider(CrawlSpider):
    name = 'csdn'
    allowed_domains = ['www.csdn.net']
    start_urls = ['https://www.csdn.net/']
    rules = (
        Rule(LinkExtractor(allow=r'Items/'), callback='parse_item', follow=True),
    )
    def parse_item(self, response):
        return item

2.CrawlSpider类介绍

3.rules规则列表

4.LinkExtractors

主要参数:

5.爬取CSDN的文章, 且提取URL和文章标题

from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
class DoubanSpider(CrawlSpider):
    name = 'csdn'
    allowed_domains = ['blog.csdn.net']
    start_urls = ['https://blog.csdn.net']
    # 指定链接提取的规律
    rules = (
        # follow:是指爬取了之后,是否还继续从该页面提取链接,然后继续爬下去
        Rule(LinkExtractor(allow=r'.*/article/.*'), callback='parse_item', follow=True),
    )
    def parse_item(self, response):
        print('-'*100)
        print(response.url)
        title = response.css('h2::text').extract()[0]
        print(title)
        print('-' * 100)
        return None

“爬虫Crawl Spider模板的用法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


网页题目:爬虫CrawlSpider模板的用法
标题路径:http://www.tsicrk.com/article/gdpeoo.html

其他资讯

让你的专属顾问为你服务

1.7084s