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

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3360|回复: 3
收起左侧

[Python 转载] scrapy框架爬取奇书网整站小说,一文学会scrapy用法!

[复制链接]
huguo002 发表于 2019-9-19 18:29
本帖最后由 huguo002 于 2019-9-19 18:36 编辑

scrapy框架爬取奇书网整站小说,一文学会scrapy用法!
scrapy框架爬取奇书网整站小说,一文学会scrapy用法!

Scrapy默认是不能在IDE中调试的,调试方法:
我们在根目录中新建一个py文件叫:entrypoint.py;在里面写入以下内容:
[Asm] 纯文本查看 复制代码
from scrapy.cmdline import execute
execute(['scrapy','crawl','qisuu'])


我这里的ide是pycham
调试直接运行 entrypoint.py 文件即可!
调试.jpg


spider爬虫主程序  qisuu.py

[Asm] 纯文本查看 复制代码
import re
import scrapy
from bs4 import BeautifulSoup
from scrapy.http import Request

class Myspider(scrapy.Spider):

    name='qisuu'
    allowed_domains=['qisuu.la']
    bash_url='https://www.qisuu.la/soft/sort0'
    bashurl='.html'

    def start_requests(self):
        for i in range(1,11):
            url=f'{self.bash_url}{str(i)}/index_1{self.bashurl}'
            yield Request(url,self.parse)

    def parse(self,response):
        max_num=re.findall(r"下一页</a>.+?<a href='/soft/sort0.+?/index_(.+?).html'>尾页</a>",response.text,re.S)[0]
        bashurl=str(response.url)[:-6]
        for i in range(1,int(max_num)+1):
            url=f'{bashurl}{str(i)}{self.bashurl}'
            yield Request(url,callback=self.get_name)

    def get_name(self,response):
        lis=BeautifulSoup(response.text,'lxml').find('div',class_="listBox").find_all('li')
        for li in lis:
            novelname=li.find('a').get_text() #小说名
            novelinformation = li.find('div', class_="s").get_text() #小说信息
            novelintroduce=li.find('div',class_="u").get_text() #小说简介
            novelurl=f"https://www.qisuu.la{li.find('a')['href']}" #小说链接
            yield Request(novelurl,callback=self.get_chapterurl,meta={'name':novelname,'url':novelurl})

    def get_chapterurl(self,response):
        #novelname =BeautifulSoup(response.text,'lxml').find('h1').get_text()
        novelname=str(response.meta['name'])
        lis=BeautifulSoup(response.text,'lxml').find('div',class_="detail_right").find_all('li')
        noveclick=lis[0].get_text() #点击次数
        novefilesize=lis[1].get_text() #文件大小
        novefiletype = lis[2].get_text()  # 书籍类型
        noveupatedate = lis[3].get_text()  # 更新日期
        novestate = lis[4].get_text()  # 连载状态
        noveauthor = lis[5].get_text()  # 书籍作者
        novefile_running_environment = lis[6].get_text()  # 运行环境
        lis=BeautifulSoup(response.text,'lxml').find('div',class_="showDown").find_all('li')
        novefile_href=re.findall(r"'.+?','(.+?)','.+?'",str(lis[-1]),re.S)[0]  #小说下载地址
        print(novelname)
        print(noveclick)
        print(novefilesize)
        print(novefiletype)
        print(noveupatedate)
        print(novestate)
        print(noveauthor)
        print(novefile_running_environment)
        print(novefile_href)








运行.gif





方法来源:崔庆才,静觅-小白进阶之Scrapy第一篇
https://cuiqingcai.com/3472.html/3

感兴趣的话可以参照尝试!
也欢迎一起交流py!
欢迎留言探讨!

如果有帮到您!可以的话免费给个评分!
每天一次评分,您随手一点,才能给予分享者更多动力!

免费评分

参与人数 2吾爱币 +3 热心值 +2 收起 理由
苏紫方璇 + 3 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
15920415252 + 1 用心讨论,共获提升!

查看全部评分

本帖被以下淘专辑推荐:

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

ZIfumaker 发表于 2019-9-19 20:19
跟着学习了
cqx754810735 发表于 2019-12-19 19:06
ghoob321 发表于 2019-12-25 09:47
您需要登录后才可以回帖 登录 | 注册[Register]

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

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

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

GMT+8, 2024-3-28 17:07

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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