python实现从网站XKCD下载全部漫画
来源:互联网 发布:windows select epoll 编辑:程序博客网 时间:2024/06/05 16:51
import requests,bs4,os
url = 'https://xkcd.com/'
#os.makedirs('xkcd',exist_ok=True)#本地目录前创建保存漫画的文件夹
i=0#下载漫画计数
while not url.endswith('#'):
#下载漫画网页,并匹配查找漫画下载路径
res = requests.get(url)
try:
resImage.raise_for_status()
except Exception as exc:
print('There was a problem:%s'%(exc))
Soup = bs4.BeautifulSoup(res.text)
comicElems = Soup.select('div#comic img')
print(comicElems[0])
if comicElems == []:
print('Could not find comic image!')
else:
comicUrl = 'http:'+str(comicElems[0].get('src'))#拼接漫画下载路径
print('Downing image %s....'%(comicUrl))
resImage = requests.get(comicUrl)
try:
resImage.raise_for_status()
except Exception as exc:
print('There was a problem:%s'%(exc))
#下载漫画存放在文件picturer中
openFile = open('C:\\Users\\Nick\\Desktop\\python\\drawing\\2\\picture\\'+str(i)+'.png','ab')#下载并重新命名
i = i+1
for chunk in resImage.iter_content(10000):
openFile.write(chunk)
openFile.close()
#拼接上一页网页路径
prevLink = Soup.select('a[rel="prev"]')[0]
url = 'https://xkcd.com/'+str(prevLink.get('href'))
print("Done!")
url = 'https://xkcd.com/'
#os.makedirs('xkcd',exist_ok=True)#本地目录前创建保存漫画的文件夹
i=0#下载漫画计数
while not url.endswith('#'):
#下载漫画网页,并匹配查找漫画下载路径
res = requests.get(url)
try:
resImage.raise_for_status()
except Exception as exc:
print('There was a problem:%s'%(exc))
Soup = bs4.BeautifulSoup(res.text)
comicElems = Soup.select('div#comic img')
print(comicElems[0])
if comicElems == []:
print('Could not find comic image!')
else:
comicUrl = 'http:'+str(comicElems[0].get('src'))#拼接漫画下载路径
print('Downing image %s....'%(comicUrl))
resImage = requests.get(comicUrl)
try:
resImage.raise_for_status()
except Exception as exc:
print('There was a problem:%s'%(exc))
#下载漫画存放在文件picturer中
openFile = open('C:\\Users\\Nick\\Desktop\\python\\drawing\\2\\picture\\'+str(i)+'.png','ab')#下载并重新命名
i = i+1
for chunk in resImage.iter_content(10000):
openFile.write(chunk)
openFile.close()
#拼接上一页网页路径
prevLink = Soup.select('a[rel="prev"]')[0]
url = 'https://xkcd.com/'+str(prevLink.get('href'))
print("Done!")
0 0
- python实现从网站XKCD下载全部漫画
- Python 批量下载xkcd漫画
- python下载漫画
- Python+selenium实现图片网站搜索后下载搜索结果的全部照片
- Python爬虫——漫画下载
- Python实现的对某漫画网站进行爬取并按本子名称储存程序
- python实现网站的js文件下载
- python实现网站内部视频批量下载
- python实现某网站的音乐下载
- python实现从豌豆荚批量下载样本
- Python轻松入门-38 从网站上下载图片
- 用Teleport Ultra下载网站全部页面
- 【Python量化投资系列】使用Python从Wind量化接口下载全部A股股票历史行情数据
- python+beautifulsoup/xpath实现新浪微博某博主全部高清大图下载器
- Java实现批量下载《神秘的程序员》漫画
- Python抓取妹子图网站全部图片
- python自学笔记(8)--Python简单爬虫从网站上下载图片和用第三方库request实现百度翻译
- python 下载整个网站
- Warning: Path must be a string . Received null Use --force to continue
- cocos中使用 websocket通信
- java中servletContextListener、httpSessionListener和servletRequestListener使用整理
- 全排列问题算法分析与实现(递归、非递归)
- Spring笔记(二)---Spring容器实例化方法
- python实现从网站XKCD下载全部漫画
- OkHttp和Volley对比
- 开发Android高德地图
- WebRTC学习之函数的异步执行
- open 系统调用分析
- 对MVC、MVP、MVVM的理解
- iOS 解决打包上传报This action could not be completed. Try again. (-22421)问题
- 人工智能提升安防应用门槛
- AndroidSDK开发步骤