1.scrapy++++一个最轻量级的scrapy爬虫(导出csv)

import scrapy,time

# scrapy shell "https://3RRvhw2" (其他系统可以使用单引号)

# scrapy runspider quotes_spider.py -o quotes.json 
# 要运行这个爬虫只需要在当前目录下的命令行输入这条命令。
# 这将会在当前目录下生成一个josn文件
class QuotesSpider(scrapy.Spider):
    name = 'quotes'
    start_urls = [
        'https://read.qidian.com/chapter/Hx0Qvc7tb9hrZK4x-CuJuw2/8jkDJBJJ6CrM5j8_3RRvhw2',
    ]
    count=0
    def parse(self, response):
        self.count+=1
        # for i in response.css()  若爬行结果里面是个列表,也就是有多个item 可以循环返回。
        yield {
            'updateTime': response.css('.j_updateTime::text').get(), #get() 等价于extract_first()
            'chapterName': response.css('.j_chapterName::text').get(),
        }
        time.sleep(1)

        if self.count<20:
            next_page = response.css('#j_chapterNext::attr("href")').get()
            if next_page is not None:
                # 应用follow很方便的创建一个跟随请求
                yield response.follow(next_page, self.parse)



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值