资源简介
改下用户名密码可以直接用,爬取VIP章节需要开通VIP,免费章节可以随便爬
代码片段和文件信息
# -*- coding: utf-8 -*-
# @Time : 2019/5/19 17:53
# @Author : LM
import requests
from bs4 import BeautifulSoup
import json
import os
import datetime
class Spider(object):
def __init__(self):
self.headers = {‘user-agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/73.0.3683.86 Safari/537.36‘}
print(‘请输入要爬取的小说名‘)
self.novel_name = input()
self.chapters_url = ‘‘
self.download_url_ls = {}
self.loginName = ‘17623609183‘
self.password = ‘liangqi520‘
def verify(self):
now = datetime.datetime.now()
start_time = datetime.datetime.strptime(‘2019-05-20 01:00:00‘ ‘%Y-%m-%d %H:%M:%S‘)
delta = now - start_time
if delta.seconds/60 > 10:
quit()
else:
print(‘验证成功‘)
def login(self):
data = {
‘loginName‘: self.loginName
‘password‘: self.password
}
login_url = ‘https://passport.17k.com/ck/user/login‘
session = requests.Session()
html = session.post(url=login_url data=data headers=self.headers).text
json_data = json.loads(html)
if json_data[‘status‘][‘msg‘] == ‘succ‘:
print(‘登陆成功,当前账户:{}‘.format(self.loginName))
return session
else:
print(‘用户名或者密码错误‘)
def catalogue(self):
url = ‘https://search.17k.com/search.xhtml?c.st=0&c.q=‘ + self.novel_name
html = requests.get(url=url headers=self.headers).text
soup = BeautifulSoup(html ‘lxml‘)
res = soup.findAll(attrs={‘class‘: ‘textmiddle‘})
for i in res:
info = i.select(‘ dl > dt > a‘)[0]
searched_name = info.get_text().strip()
if searched_name == self.novel_name:
print(‘{}:查找成功‘.format(self.novel_name))
self.chapters_url = ‘https://‘ + info.get(‘href‘)[2:].replace(‘book‘ ‘list‘)
break
print(‘查找失败,不存在该小说或拼写错误‘)
def get_download_url(self):
html = requests.get(url=self.chapters_url headers=self.headers)
html.encoding = ‘utf-8‘
soup = BeautifulSoup(html.text ‘lxml‘)
volume = soup.find_all(‘dl‘ c
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论