scrapy 爬取起点中文网首页的本周强推作品的详情介绍

scrapy 爬取起点中文网首页的每周强推作品的详情介绍

在这里插入图片描述

从列表页跳转到详情页

在这里插入图片描述

保存的数据

封面图

小说名

作者

类型

简介

import scrapy

# 起点首页  本周推荐
class WeektjSpider(scrapy.Spider):
    name = 'weekTJ'
    allowed_domains = ['qidian.com']
    start_urls = ['http://qidian.com/']

    def parse(self, response):
        titles = response.css(".book-list-wrap")
        for title in titles:
            # print(title.extract())
            # print(title.css(".book-list-wrap h3::text").extract())
            title_arr = title.css(".book-list-wrap h3::text").extract()
            if("本周强推" in title_arr):
                # print(title_arr)

                # 作者列表 剔除广告
                # list = title.css(".author::text").extract()
                # 这里我直接在 a 标签的 href 里面 做判断
                # print(list)
                # print(title.extract())
                xiaoshuo_names = title.css(".name::attr(href)").extract()

                for href in xiaoshuo_names:
                    # 剔除游戏广告 先将 href 转小写
                    if 'game' not in (href.lower()):
                        yield scrapy.Request(url= "http:"+href, callback=self.new_parse)
    def new_parse(self, response):
        details = response.css(".book-detail-wrap")
        for detail in details:
            # 去掉img  \n
            img = detail.css("#bookImg img::attr(src)").extract()[0]
            if "\n" in img:
                img = img[0:-1]

            info = {
                "img": "http:"+ img,
                "title": detail.xpath("//div/div/h1/em/text()").get(),
                "author": detail.css(".writer::text").extract()[0],
                "type": detail.css(".book-info .tag a::text").extract(),
                # html 标签
                "remark": detail.css(".intro::text").extract()[0]
            }
            print(info)


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值