爬起点小说 day02
总的来说起点小说还是挺好爬的,就是爬取小说的时候太慢了,4000多本小说就爬了2天一夜
首先爬取的是网页的所有类别,并把类别名存入到mongodb中,链接存到redis中:
import scrapy
from bson.objectid import ObjectId
from scrapy.http import Request
from qidianNovel.spiders.connectionSQL import getredis,getMongodb
# 把起点首页的所有列表
class spider_list(scrapy.Spider):
name = "spider_list" #要调用的名字
allowed_domains = ["qidian.com"] #分一个域
start_urls = [#所有要爬路径
"https://www.qidian.com/all?orderId=&page=1&style=1&pageSize=20&siteid=1&pubflag=0&hiddenField=0"
]
#每爬完一个网页会回调parse方法
def parse(self, response):
hx=response.xpath('//div[@class="work-filter type-filter"]/ul/li/a|//div[@class="work-filter type-filter"]/ul/li/a')
for i in range(1,len(hx)):
print(hx[i].select("text()").extract()[0]) # 取长度
Pid=self.insertMongodb(hx[i].select("text()").extract()[0],None)
url="https:"+hx[i].select("@href").extract()[0]
print(url)
request=Request(url,callback=lambda response,Pid=str(Pid):self.detail_list(response,Pid))
yield request
def detail_list(self,response,Pid):
links = response.xpath('//div[@class="sub-type"]/dl[@class=""]/dd/a')
pid=ObjectId(Pid)
for link in links:
print("***************")
print(link.select("text()").extract()[0])
print(link.select('@href').extract()[0])
print("***************")
cid=self.insertMongodb(link.select("text()").extract()[0],pid)
href="https:" + link.select('@href').extract()[0]
self.pushRedis(pid,cid,href)
def insertMongodb(self,className,pid):
bcollection = getMongodb('novel', 'boy_list')
id = bcollection.insert({'list_name': className, 'pid': pid})
return id
def pushRedis(self,pid,cid,href):
red = getredis()
href="%s,%s,%s" %(pid,cid,href)
red.lpush('bnovel_all_list',href)
爬起点小说 day02的更多相关文章
- 爬起点小说 day01
先介绍下我自己爬起点小说的思路: 1.爬取所有的类型列表 a.链接存redis中 类型表:novel_list 具体每一种类型:bnovel_all_list(把novel_list和bnovel_l ...
- 爬起点小说day03
# 把所有类别的前3页的小说爬取下来 import scrapyfrom scrapy.http import Requestfrom time import sleepfrom qidianNove ...
- Python实战项目网络爬虫 之 爬取小说吧小说正文
本次实战项目适合,有一定Python语法知识的小白学员.本人也是根据一些网上的资料,自己摸索编写的内容.有不明白的童鞋,欢迎提问. 目的:爬取百度小说吧中的原创小说<猎奇师>部分小说内容 ...
- python爬虫——爬取小说 | 探索白子画和花千骨的爱恨情仇(转载)
转载出处:药少敏 ,感谢原作者清晰的讲解思路! 下述代码是我通过自己互联网搜索和拜读完此篇文章之后写出的具有同样效果的爬虫代码: from bs4 import BeautifulSoup imp ...
- python之爬取小说
继上一篇爬取小说一念之间的第一章,这里将进一步展示如何爬取整篇小说 # -*- coding: utf- -*- import urllib.request import bs4 import re ...
- 用Python爬取小说《一念永恒》
我们首先选定从笔趣看网站爬取这本小说. 然后开始分析网页构造,这些与以前的分析过程大同小异,就不再多叙述了,只需要找到几个关键的标签和user-agent基本上就可以了. 那么下面,我们直接来看代码. ...
- Scrapy爬取小说简单逻辑
Scrapy爬取小说简单逻辑 一 准备工作 1)安装Python 2)安装PIP 3)安装scrapy 4)安装pywin32 5)安装VCForPython27.exe ........... 具体 ...
- 初次尝试python爬虫,爬取小说网站的小说。
本次是小阿鹏,第一次通过python爬虫去爬一个小说网站的小说. 下面直接上菜. 1.首先我需要导入相应的包,这里我采用了第三方模块的架包,requests.requests是python实现的简单易 ...
- python3下BeautifulSoup练习一(爬取小说)
上次写博客还是两个月以前的事,今天闲来无事,决定把以前刚接触python爬虫时的一个想法付诸行动:就是从网站上爬取小说,这样可以省下好多流量(^_^). 因为只是闲暇之余写的,还望各位看官海涵:不足之 ...
随机推荐
- python从FTP下载文件
#!/usr/bin/python # -*- coding: utf-8 -*- """ FTP常用操作 """ from ftplib ...
- Oracle导出数据EXP00106错误
在导出dmp文件的时候(命令:exp 用户名/密码@IP/实例名 file=D:\20180910.dmp log=D:\20180910.log),遇到以下错误: 错误原因: 导出使用的是Orac ...
- ES6 export
一.默认导出(default export)// 1.一个模块只能有一个默认导出, 对于默认导出, 导入的名称可以和导出的名称不一致, 这对于导出匿名函数或类非常有用. <!---- page. ...
- tcp的粘包和拆包示例以及使用LengthFieldFrameDecoder来解决的方法
粘包和拆包是什么? TCP协议是一种字节流协议,没有记录边界,我们在接收消息的时候,不能人为接收到的数据包就是一个整包消息 当客户端向服务器端发送多个消息数据的时候,TCP协议可能将多个消息数据合并成 ...
- Dagger2 导入项目
导入分为两步: 第一步: 在Project build.gradle 文件中加入: dependencies { // Dagger2 第一步classpath 'com.neenbedankt.gr ...
- 史上最完整的Android开发工具集合(转)
需要的:戳这里:http://www.apkbus.com/thread-252748-1-1.html
- 个人小爱好:Operating System:three easy pieces---第6章第4节_担心并发问题?
担心并发问题? 微妙,上下文切换大约6微妙.而,现在的系统有着级数级别的提升,在2-3GHz的处理起中消耗只有亚微妙级. 但应该注意到,不是所有的系统性能都跟着CPU性能的提升而提升,根据Ouster ...
- Gym 101981J - Prime Game - [数学题][线性筛+分解质因数][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem J]
题目链接:http://codeforces.com/gym/101981/attachments 题意: 令 $mul(l,r) = \prod_{i=l}^{r}a_i$,且 $fac(l,r)$ ...
- Gym 101873C - Joyride - [最短路变形][优先队列优化Dijkstra]
题目链接:http://codeforces.com/gym/101873/problem/C 题意: 这是七月的又一个阳光灿烂的日子,你决定和你的小女儿一起度过快乐的一天.因为她真的很喜欢隔壁镇上的 ...
- emoji表情softbank和unicode不兼容解决方案
https://blog.ernest.me/post/emoji-remapping-solution