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) ...
随机推荐
- SpringMVC 三种异常处理方式
SpringMVC 三种异常处理方式 在 SpringMVC, SpringBoot 处理 web 请求时, 若遇到错误或者异常,返回给用户一个良好的错误信息比 Whitelabel Error Pa ...
- ASP.NET Core中使用Csp标头对抗Xss攻击
内容安全策略(CSP)是一个增加的安全层,可帮助检测和缓解某些类型的攻击,包括跨站点脚本(XSS)和数据注入攻击.这些攻击用于从数据窃取到站点破坏或恶意软件分发的所有内容(深入CSP) 简而言之,CS ...
- CodeForces 780 E Underground Lab
Underground Lab 题解: 如果遍历一棵树,我们可以发现最多需要走的步数也不会超过2 * n步. 所以我们选出一棵树,然后遍历一边这颗树. 然后把序列分成k块就好了. 代码: #inclu ...
- POJ 2491 Scavenger Hunt map
Scavenger Hunt Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2848 Accepted: 1553 De ...
- java-冒泡排序笔记
//冒泡排序public class BubbleSort { // public static void main(String[] args) {// // TODO 自 ...
- 关于Math常用的方法
1. 常用的Math用法 Math.random() //0-1 的随机数 Math.round() //四舍五入取整 Math.ceil() //向上取整 Math.floor() //向下取整 M ...
- kubernetes Value:将磁盘挂载到容器,PV,PVC
6.1.介绍卷 6.1.1.卷的类型 emptyDir-用于存储临时数据的简单空目录 hostPath-用于将目录从工作节点的文件系统挂载到pod nfs-挂载到pod中的NFS共享卷. 还有其他的如 ...
- CVE-2014-6271 Shellshock 破壳漏洞 复现
补坑. 什么是shellshock ShellShock是一个BashShell漏洞(据说不仅仅是Bash,其他shell也可能有这个漏洞). 一般情况来说,系统里面的Shell是有严格的权限控制的, ...
- git bash 界面修改成linux界面
在使用git bash操作git时,$符总是另起一行,给人感觉特别不爽,特别想修改成linux下一样的风格. 在git输入命令: vim ~/.bash_profile 进入insert模式,添加内容 ...
- Java Web总结(一)-- 入门
一.基本概念 1.1.WEB开发的相关知识 WEB,在英语中web即表示网页的意思,它用于表示Internet主机上供外界访问的资源. Internet上供外界访问的Web资源分为: 静态web资源( ...