纵横小说

# -*- coding: utf-8 -*-
import scrapy
from ..items import BookItem


class ZhSpider(scrapy.Spider):
    name = 'zh'
    allowed_domains = ['zongheng.com']
    start_urls = ['http://book.zongheng.com/quanben/c0/c0/b9/u0/p1/v9/s1/t0/ALL.html']


    def parse(self, response):


        lis = response.xpath('//ul[@class="main_con"]/li')


        for li in lis:
            # 判断是否为包含小说信息的li标签
            if li.xpath('@class').extract_first('') == '':
                # 从li中提取数据
                # 小说类型
                novel_type = li.xpath('span[@class="kind"]/a/text()').extract_first('未知')
                # 小说名称
                novel_name = li.xpath('span/a[@class="fs14"]/text()').extract_first('')
                # 小说字数
                novel_number = li.xpath('span[@class="number"]/text()').extract_first('')
                # 去除数据中的特殊符号
                novel_number = novel_number.replace('\n','')
                novel_number = novel_number.replace('\r','')
                novel_number = novel_number.replace('\t','')
                # 小说作者
                novel_author = li.xpath('span[@class="author"]/a/text()').extract_first('匿名')
                # 更新时间
                update_time = li.xpath('span[@class="time"]/text()').extract_first('已完结')
                # 去除数据中的特殊符号
                update_time = update_time.replace('\n','')
                update_time = update_time.replace('\r','')
                update_time = update_time.replace('\t','')


                # 创建item对象
                item = BookItem()
                item['novel_type'] = novel_type
                item['novel_name'] = novel_name
                item['novel_number'] = novel_number
                item['novel_author'] = novel_author
                item['update_time'] = update_time


                yield item











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值