吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 820|回复: 2
收起左侧

[讨论] 小白每日一爬 Crawlspider练习 (发现正则不会写)

[复制链接]
lihu5841314 发表于 2021-5-30 14:44
[Asm] 纯文本查看 复制代码
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule


class ZxSpider(CrawlSpider):
    name = 'zx'
    allowed_domains = ['zzxrjc.com']
    start_urls = ['http://zzxrjc.com/']

    rules = (
        Rule(LinkExtractor(allow=r'(/txt/\d+/)'), callback='parse_item'),
        Rule(LinkExtractor(allow=r'(/sort/\d+/)'),  follow=True),
    )

    def parse_item(self, response):
        item = {}
        item['book_img'] = response.xpath('//div[@class="novel_info_main"]/img/@src').extract_first()
        item['book_name'] = response.xpath('//div[@class="novel_info_main"]/img/@alt').extract_first()
        item['book_detail'] = response.xpath('//div[@id="info"]/div[1]//text()').extract_first()
        print(item)
        return item

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| lihu5841314 发表于 2021-5-30 14:45
知轩藏书  比上一贴少了好多代码 Rules 真好用
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-17 06:23

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表