漫画链接:https://www.manhuadb.com/manhua/324

建议:早上爬,速度较快。

天下无双宫本武藏

代码

# https://www.manhuadb.com/manhua/324

import os
import re
import time
import requests
from requests import codes
from bs4 import BeautifulSoup
from requests import RequestException def get_page(url):
try:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36'
+ '(KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.text
return 'status_code = ' + str(status_code)
except RequestException:
return 'RequestException' def get_pagesNumber(text):
soup = BeautifulSoup(text, 'lxml')
pagesNumber = soup.find(name='div', class_="d-none vg-r-data")
return pagesNumber.attrs['data-total'] def parse_page(text):
soup = BeautifulSoup(text, 'lxml')
url = soup.find(name='img', class_="img-fluid show-pic")
chapter = soup.find(name='h2', class_="h4 text-center")
page = soup.find(name='span', class_="c_nav_page")
yield {
'url': url['src'],
'chapter': chapter.get_text(),
'page': page.get_text()
} def save_image(item):
img_path = '浪客行' + os.path.sep + item.get('chapter') #os.path.sep是路径分隔符\
if not os.path.exists(img_path):
os.makedirs(img_path)
try:
resp = requests.get(item.get('url'))
if codes.ok == resp.status_code:
file_path = img_path + os.path.sep + '{file_name}.{file_suffix}'.format(
file_name=item.get('chapter')[-2:]+'-'+item.get('page'), file_suffix='jpg')
if not os.path.exists(file_path):
with open(file_path, 'wb') as f:
f.write(resp.content)
print('Downloaded image path is %s' % file_path)
else:
print('Already Downloaded', file_path)
except Exception as e:
print(e) if __name__ == '__main__':
for chapter in range(3678, 3715): #共37章节,3678到3714
base_url = 'https://www.manhuadb.com/manhua/324/320_'+str(chapter)
text = get_page(base_url+'.html')
pagesNumber = get_pagesNumber(text) #获取当前章节总页数
for page in range(1, int(pagesNumber)+1):
url = base_url+'_'+str(page)+'.html'
text = get_page(url)
for item in parse_page(text):
save_image(item)

爬取漫画DB上的《浪客行》的更多相关文章

  1. 爬取漫画DB上的JoJo的奇妙冒险 第七部 飙马野郎

    SBR是JOJO系列我最喜欢的一部,所以今天把漫画爬取到本地,日后慢慢看. import re import time import requests from requests import cod ...

  2. python爬取漫画

    抓取漫画的网址是:sf互动传媒 抓取漫画的由来也是看了知乎上有人说用爬取漫画,然后自己也玩玩 首页中每个漫画的url是类似这样存储的: <tr> <td height="3 ...

  3. 【Python3 爬虫】14_爬取淘宝上的手机图片

    现在我们想要使用爬虫爬取淘宝上的手机图片,那么该如何爬取呢?该做些什么准备工作呢? 首先,我们需要分析网页,先看看网页有哪些规律 打开淘宝网站http://www.taobao.com/ 我们可以看到 ...

  4. 爬取拉钩网上所有的python职位

    # 2.爬取拉钩网上的所有python职位. from urllib import request,parse import json,random def user_agent(page): #浏览 ...

  5. 使用BeautifulSoup 爬取一个页面上的所有的超链接

    # !/usr/bin/python # -*-coding:utf-8-*- import urllib from bs4 import BeautifulSoup response = urlli ...

  6. Python 002- 爬虫爬取淘宝上耳机的信息

    参照:https://mp.weixin.qq.com/s/gwzym3Za-qQAiEnVP2eYjQ 一般看源码就可以解决问题啦 #-*- coding:utf-8 -*- import re i ...

  7. python3爬虫-爬取58同城上所有城市的租房信息

    from fake_useragent import UserAgent from lxml import etree import requests, os import time, re, dat ...

  8. Python爬取知乎上搞笑视频,一顿爆笑送给大家

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:Huangwei AI 来源:Python与机器学习之路 PS:如有需 ...

  9. 利用python3 爬取 网易云 上 周杰伦所有专辑,歌曲,评论,并完成可视化分析已经歌曲情绪化分析

    这篇文章适合于python爱好者,里面可能很多语句是冗长的,甚至可能有一些尚未发现的BUG,这个伴随着我们继续学习来慢慢消解吧.接下来 我把里面会用到的东西在这里做一个简单总结吧:本文用到了两门解释性 ...

随机推荐

  1. C#系列之算数运算符(四)

    今天,我将做一个算术运算符++和--的笔记以及一元运算符和二元运算符同时存在怎么计算的笔记 ++:分为前加加和后加加,但是最后结果都是+1: --:分为前减减和后减减,但是最后结果都是-1: 例如: ...

  2. 深入浅出 Serverless:优势、意义与应用

    Serverless 是炙手可热的技术,被认为是云计算发展的未来方向.尤其是在前端研发领域,使用 Node 开发云函数,可以让前端工程师更加专注于业务逻辑,实现全栈工程师的角色转变. Serverle ...

  3. 百度MP3音乐API接口及应用

    当你在百度去搜索一首歌时,你会发现有种更简单的方法. http://box.zhangmen.baidu.com/x?op=12&count=1&title=歌名$$作者$$$$ 例如 ...

  4. Codeforces_712_B

    http://codeforces.com/problemset/problem/712/B 水,判断奇偶即可. #include<iostream> #include<string ...

  5. JUC中的锁

    ★.不同角度的锁的理解: #1.公平锁.非公平锁 公平锁:eg: ReentrantLock 关键词:先来先服务. 加锁前检查是否有排队等锁的线程,若有,当前线程参与排队,先排的线程优先获取锁.相对没 ...

  6. [C/C++]const限定符总结

    const限定符 const是一种限定符,被const所限定的变量其值不可以被改变. const的初始化 由于const一旦创建其值就不能够被改变,所以我们必须对其进行初始化 const int a; ...

  7. 2020年,手把手教你如何在CentOS7上一步一步搭建LDAP服务器的最新教程

    同步滚动:关 什么是LDAP 什么是LDAP? 要想知道一个概念,最简单的办法就是wikipedia,当然也可以百科. LDAP全称是轻型目录访问协议(Lightweight Directory Ac ...

  8. Linux 邮件服务

    三个要点 1.smtp协议 2.搭建本地邮件服务器 3.使用外部邮件服务器 实现邮件功能 1.smtp协议           SMTP(Simple Mail Transfer Protocol)即 ...

  9. Mybatis随记(一)update动态SQL

    <update id="updateUser"> UPDATE user_info SET <if test="gzhOpenId != null an ...

  10. centos7上安装docker社区版

    container(容器) docker(集装箱) 容器的优点 1. 启动速度快 2. 节省资源 3. 兼容性高 保证机器正常上网 #ping www.baidu.com CPU需要支持虚拟化 # g ...