scrapy 爬取小说
QiushuSpider
# -*- coding: utf-8 -*-
import scrapy
import time
from qiushu.items import QiushuItem class QiushuspiderSpider(scrapy.Spider):
name = 'QiushuSpider'
allowed_domains = ['www.qiushu.cc']
start_urls = ['http://www.qiushu.cc/'] def parse(self, response):
'''解析分类列表'''
# TODO 解析分类
# 分类URLs
links = response.xpath('//p[@class="hot_tips"]/a/@href').extract()
# 所有类型链接
for i in links:
url = 'http://www.qiushu.cc' + i
yield scrapy.Request(url, callback=self.parse_books, dont_filter=True) def parse_books(self, response):
'''解析书籍列表'''
# TODO: 解析书籍列表
# time.sleep(2)
book_url = []
for i in response.xpath('//*[@id="main"]/div[1]/div/div/ul/li'):
book_dan_url = ''.join(i.xpath('.//span[@class="t1"]/a/@href').extract_first())
book_url.append(book_dan_url)
print('*' * 30, book_dan_url)
# import ipdb as pdb; pdb.set_trace()
print('*' * 30, book_url)
for i in book_url:
yield scrapy.Request(i, callback=self.parse_section, dont_filter=True)
# TODO: 处理下一页
xia_url = ''.join(response.xpath('//*[@class="next"]/@href').extract())
if bool(xia_url):
yield scrapy.Request(xia_url, callback=self.parse_books, dont_filter=True) def parse_section(self, response):
'''解析具体的某一章'''
# TODO: 解析具体的章
item = QiushuItem()
# 书名
item['name'] = ''.join(response.xpath('//div[@class="title"]/h1/text()').extract())
# 作者
item['author'] = ''.join(response.xpath('//div[@class="title"]/span/text()').extract())
# 书籍分类标签
item['booktype'] = ''.join(response.xpath('//*[@id="main"]/div[2]/text()[2]').extract()).split('>')[1]
# 书籍状态
item['state'] = ''.join(response.xpath('//*[@id="main"]/div[2]/span/text()').extract())
# 书籍的有效地址
item['showUrl'] = response.url
# 书籍描述
item['describe'] = ''.join(response.xpath('//div[@class="intro"]/p/text()').extract())
yield item
items
# -*- coding: utf-8 -*- # Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html import scrapy class QiushuItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
# 书名
name = scrapy.Field()
# 作者
author = scrapy.Field()
# 书籍分类标签
booktype = scrapy.Field()
# 书籍状态
state = scrapy.Field()
# 书籍的有效地址
showUrl = scrapy.Field()
# 书籍描述
describe = scrapy.Field()
scrapy 爬取小说的更多相关文章
- Scrapy爬取小说简单逻辑
Scrapy爬取小说简单逻辑 一 准备工作 1)安装Python 2)安装PIP 3)安装scrapy 4)安装pywin32 5)安装VCForPython27.exe ........... 具体 ...
- scrapy爬取小说盗墓笔记
# -*- coding: utf-8 -*- import scrapy from daomu.items import DaomuItem class DaomuspiderSpider(scra ...
- 小说免费看!python爬虫框架scrapy 爬取纵横网
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 风,又奈何 PS:如有需要Python学习资料的小伙伴可以加点击下方 ...
- 以豌豆荚为例,用 Scrapy 爬取分类多级页面
本文转载自以下网站:以豌豆荚为例,用 Scrapy 爬取分类多级页面 https://www.makcyun.top/web_scraping_withpython17.html 需要学习的地方: 1 ...
- scrapy 爬取纵横网实战
前言 闲来无事就要练练代码,不知道最近爬取什么网站好,就拿纵横网爬取我最喜欢的雪中悍刀行练手吧 准备 python3 scrapy 项目创建: cmd命令行切换到工作目录创建scrapy项目 两条命 ...
- Python实战项目网络爬虫 之 爬取小说吧小说正文
本次实战项目适合,有一定Python语法知识的小白学员.本人也是根据一些网上的资料,自己摸索编写的内容.有不明白的童鞋,欢迎提问. 目的:爬取百度小说吧中的原创小说<猎奇师>部分小说内容 ...
- Scrapy爬取美女图片 (原创)
有半个月没有更新了,最近确实有点忙.先是华为的比赛,接着实验室又有项目,然后又学习了一些新的知识,所以没有更新文章.为了表达我的歉意,我给大家来一波福利... 今天咱们说的是爬虫框架.之前我使用pyt ...
- 【转载】教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神
原文:教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神 本博文将带领你从入门到精通爬虫框架Scrapy,最终具备爬取任何网页的数据的能力.本文以校花网为例进行爬取,校花网:http:/ ...
- scrapy爬取西刺网站ip
# scrapy爬取西刺网站ip # -*- coding: utf-8 -*- import scrapy from xici.items import XiciItem class Xicispi ...
随机推荐
- Google推出了Python最牛逼的编辑器
环境配置对于大多数人来说都是拦路虎,我们小白往往不知道: 怎么正确的安装 不知道选择什么 怎么安装常用的第三方库 ... Google推出了一个在线的网站 https://colab.research ...
- JAVA 数组遍历
一.遍历List 1.增强for循环 String[] arr = new String[] {"xx","yy","zz"}; for(S ...
- The requested URL /xxxx.html was not found on this server
The requested URL /xxxx.html was not found on this server 的原因是,Apache没有开启重写 apache 打开 httpd.conf 文件找 ...
- 通过Loadruner对mysql数据库进行增删改查
操作mysql数据库,是在实现mysql数据源配置的基础上操作,可先阅读:loadrunner参数化使用mysql数据源失败解决方法 写之前先理一下,数据库访问流程:打开数据库 --> 数据库 ...
- bootstrap-datetimepicker 时间配置,包含颜色
if ($('.isdatetimepicker')!=undefined&&$('.isdatetimepicker').datetimepicker!=undefined) { / ...
- OJ每日一练试水第1天,聊聊输入输出问题
目录 多组输入 第一题 多组冒泡排序 (难度2颗星版本) (难度3颗星版本) (难度4颗星版本) scanf返回值 时间:2019.4.26 @( 每日一练01) 先借鉴一下ACM的输入格式 OJ题中 ...
- C#调用C++的DLL 尝试写入受保护的内存
原因:C#中的声明函数的参数类型与C++的函数的参数类型不一致,在参照C#与C++的参数类型对照表以后,修改相应参数类型,问题解决
- Django应用app创建及ORM
一.重要知识点回顾: 1. form表单提交数据的注意事项: 1. 是form不是from,必须要有method和action (action用来指定你的数据提交到后台哪个地方,method用来指定你 ...
- elk报警监控之sentinl 钉钉+邮件告警
注:我的elk sentinl版本都是6.5.1 前期知识 es的查询语法.es watcher使用方法. https://www.cnblogs.com/pilihaotian/p/5830754. ...
- [Docker] 容器持久化数据的首选机制 Volume
Volume 是 docker 容器生成持久化数据的首选机制.bind mounts 依赖主机机器的目录机构,volume 完全由 docker 管理.volume 较 bind mounts 有几个 ...