python爬取哦漫画
import requests
from lxml import etree
from bs4 import BeautifulSoup
import os
from selenium import webdriver #解析每个漫画分页并下载漫画
def manhua(url): browser.get(url) #获取模拟访问的页面源码
html=browser.page_source html = etree.HTML(html)
img_url = html.xpath('//img[@id="mangaFile"]/@src')[0]
alt = html.xpath('/html/body/div[2]/div[2]/h1/a/text()')[0]
title = html.xpath('/html/body/div[2]/div[2]/h2/text()')[0]
print(img_url,alt,title) # print(html) path='./漫画/'+alt+'/'+title+'/'
if not os.path.exists(path):
os.makedirs(path)
fname=img_url.split('/')[-1]
# print(fname) print(os.path.join(path,fname)) # request.urlretrieve(img_url,os.path.join(path,fname)) #请求图片地址
response = requests.get(img_url)
#二进制解码
data= response.content
#保存文件
with open(path+fname,'wb') as f:
f.write(data)
#解析获取漫画分页链接
def manhua_url(url):
response = requests.get(url)
response.encoding = response.apparent_encoding
html = response.text
html = etree.HTML(html)
# print(html)
#i为漫画页数
i = html.xpath('/html/body/div[2]/div[2]/span/text()')[1][1:-1]
i=int(i)
# print(i)
#找到分页规律
#拼接分页链接,选择用format函数
url = url +'/index.html?p={}'
# print(url)
for n in range(1,i+1):
fullurl = url.format(n)
print(fullurl)
# time.sleep(2)
#fullurl为所有的分页漫画链接
manhua(fullurl) #解析列表页
def list(lb_url):
response = requests.get(lb_url)
response.encoding = response.apparent_encoding
html = response.text
html = BeautifulSoup(html,'lxml')
#匹配所有章节链接
url_list = html.select('div.subBookList ul li')
for url in url_list :
url = url.select('a')[0].get('href').split('/')[-2] # print(url)
fullurl = os.path.join(lb_url,url)
print(fullurl)
#章节链接
manhua_url(fullurl) # print(url_list)
# print(html) #解析首页
def shouye():
#首页链接
base_url = 'http://www.omanhua.com/'
#发起请求
response = requests.get(base_url)
#解码
response.encoding = response.apparent_encoding
#获取返回的网页
html = response.text
# print(html)
#解析
html =BeautifulSoup(html,'lxml')
#匹配最热漫画链接
url_list = html.select('ul#cartoon_image_show1 li')
for url in url_list:
# print(url)
url = url.select('a')[0].get('href')[1:]
# alt = url.select('a')
# print(alt)
#拼接链接
fullurl = os.path.join(base_url,url)
print(fullurl) list(fullurl)
if __name__ == '__main__':
# 用自动测试模块selenium模拟浏览器访问,这里用谷歌 图片加载获取不到图片链接
#后面的路径是chorm驱动路径
browser = webdriver.Chrome(executable_path=r'C:\Users\zhaozhi\Desktop\chromedriver.exe')
shouye() 刚开始自学爬虫不久,代码可能写的有点繁琐,希望和大家一起学习学习进步
python爬取哦漫画的更多相关文章
- Node.js/Python爬取网上漫画
某个周日晚上偶然发现了<火星异种>这部漫画,便在网上在线看了起来.在看的过程中图片加载很慢,而且有时候还不小心点到广告,大大延缓了我看的进度.后来想到能不能把先把漫画全部抓取到本地再去看. ...
- Python 爬取所有51VOA网站的Learn a words文本及mp3音频
Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...
- python爬取网站数据
开学前接了一个任务,内容是从网上爬取特定属性的数据.正好之前学了python,练练手. 编码问题 因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这个机会算是彻底搞清楚了. 问题要从文字的编码讲 ...
- python爬取某个网页的图片-如百度贴吧
python爬取某个网页的图片-如百度贴吧 作者:vpoet mail:vpoet_sir@163.com 注:随意copy,不用告诉我 #coding:utf-8 import urllib imp ...
- Python:爬取乌云厂商列表,使用BeautifulSoup解析
在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...
- 使用python爬取MedSci上的期刊信息
使用python爬取medsci上的期刊信息,通过设定条件,然后获取相应的期刊的的影响因子排名,期刊名称,英文全称和影响因子.主要过程如下: 首先,通过分析网站http://www.medsci.cn ...
- python爬取免费优质IP归属地查询接口
python爬取免费优质IP归属地查询接口 具体不表,我今天要做的工作就是: 需要将数据库中大量ip查询出起归属地 刚开始感觉好简单啊,毕竟只需要从百度找个免费接口然后来个python脚本跑一晚上就o ...
- Python爬取豆瓣指定书籍的短评
Python爬取豆瓣指定书籍的短评 #!/usr/bin/python # coding=utf-8 import re import sys import time import random im ...
- python爬取网页的通用代码框架
python爬取网页的通用代码框架: def getHTMLText(url):#参数code缺省值为‘utf-8’(编码方式) try: r=requests.get(url,timeout=30) ...
随机推荐
- ACdream1726-A Math game+(DFS+二分)+(DFS+前缀和)
传送门 官方题解:http://acdream.info/topic?tid=4246 参考:https://www.cnblogs.com/nowandforever/p/4492428.html ...
- HDU1814Peaceful Commission求2-sa最小字典序
#include <iostream> #include <cstdio> #include <vector> #include <cstring> # ...
- 牛客小白月赛4 C 病菌感染 dfs
链接:https://www.nowcoder.com/acm/contest/134/C来源:牛客网 题目描述 铁子和顺溜上生物课的时候不小心将几滴超级病菌滴到了培养皿上,这可急坏了他们. 培养皿可 ...
- 那些年,我们误解的 JavaScript 闭包
说到闭包,大部分的初始者,都是谈虎色变的.最近对闭包,有了自己的理解,就感觉.其实我们误解闭包.也被网上各种说的闭包的解释给搞迷糊. 一句话:要想理解一个东西还是看权威的东西. 下面我来通俗的讲解一个 ...
- 基础知识:CSRF漏洞
CSRF漏洞概述 CSRF漏洞是跨站请求伪造攻击,能够对攻击用户的增.删.改,不能攻击查.为什么呢?根据其原理,攻击者是发一个链接给用户,用户点击这个链接而执行危险的操作,信息并不会返回到攻击者的电脑 ...
- 原创 | 手摸手带您学会 Elasticsearch 单机、集群、插件安装(图文教程)
欢迎关注笔者的公众号: 小哈学Java, 每日推送 Java 领域干货文章,关注即免费无套路附送 100G 海量学习.面试资源哟!! 个人网站: https://www.exception.site/ ...
- Java,Python,前端,Linux,公众号等5T编程资源整理免费下载
场景 我的CSDN: https://blog.csdn.net/BADAO_LIUMANG_QIZHI 实现 马士兵Java学习视频 方立勋JavaWeb 尚硅谷Python核心基础 数据分析 机器 ...
- js 中 undefined、NaN、null
undefined 即未定义 js 中 没有声明 或者 声明后未赋值的变量 用typeof判断后类型都是 undefined 但是直接console.log( ) 输出的话 没有声明的变量会报错:而声 ...
- response对响应的设置
1.response对象设置响应行状态码: protected void doGet(HttpServletRequest request, HttpServletResponse response) ...
- MOOC C++笔记(三):类和对象提高
第三周:类和对象提高 this指针 作用 this指针作用就是指向成员函数所作用的对象. 非静态成员函数中可以直接使用this来代表指向该函数作用的指针. 成员函数中默认有一个this指针指向当前对象 ...