学习小记 - Python爬虫 (3) 利用Python爬取wanimal所有图片
来源:互联网 发布:win7搜不到网络打印机 编辑:程序博客网 时间:2024/05/21 18:35
这是辆车…
本次调用urlretrieve()方法实现对媒体文件的本地存储,其他和之前类似。
from urllib.request import urlopen, urlretrievefrom bs4 import BeautifulSoupfrom urllib.error import URLError, HTTPErrorimport requestsclass Wanimal: def __init__(self, page): self.page = page self.imgs = [] def getPage(self, page): try: html = urlopen("http://wanimal1983.org/page/"+str(page)) bsobj = BeautifulSoup(html, "html.parser") return bsobj except (URLError, HTTPError) as e: print (e) return None def getImages(self, page): print ("正在加载第%d页" % page) bsobj = self.getPage(page) imgTags = bsobj.findAll("div", {"class": "photo-sets"}) self.imgs = [] for imgTag in imgTags: for img in imgTag.findAll("img"): self.imgs.append(img) def download(self): for page in range(self.page): self.getImages(page+1) for i in range(len(self.imgs)): print ("正在保存第%d个图片" % (i+1)) path = str(page)+'_'+str(i)+".jpg" print (self.imgs[i].attrs["src"]) urlretrieve(self.imgs[i].attrs["src"], "wanimal/"+path)w = Wanimal(100000)print (w.imgs)w.download()
由于Ubutun下不能全局翻墙(我不会><),本次代码在windows下运行。
代码跑起来咯~!
0 0
- 学习小记 - Python爬虫 (3) 利用Python爬取wanimal所有图片
- PYTHON爬取WANIMAL图片
- python爬虫爬取图片
- python网络爬虫学习(六)利用Pyspider+Phantomjs爬取淘宝模特图片
- python学习(4):python爬虫入门案例-爬取图片
- Python爬虫学习笔记(1):简单的图片爬取
- python 爬虫爬取所有上市公司公告信息(一)
- python 爬虫爬取所有上市公司公告信息(二)
- python 爬虫爬取所有上市公司公告信息(三)
- python 爬虫爬取所有上市公司公告信息(四)
- python 爬虫爬取所有上市公司公告信息(五)
- python 3.3 爬虫之爬取图片
- python爬虫爬取美女图片
- 《python爬虫实战》:爬取图片
- python爬虫-爬取美女图片
- python网络爬虫爬取图片代码
- Python爬虫爬取百度图片
- python爬虫实战 爬取天极图片
- 分页一
- Gson解析异常,请求大神解惑,感激不尽啊
- gitbash一直报:sh: __git_ps1: command not found的解决办法 ---待验证
- 关于cocos2dxActivity监听不到返回健的问题
- 【凡凡说项目】挑一件事情坚持下去
- 学习小记 - Python爬虫 (3) 利用Python爬取wanimal所有图片
- android sdk 更新可用的
- Android Studio 的项目怎么导入Eclipse
- Linux内核的list_head民用改造
- 753 A. Santa Claus and Candies
- eclipse 插件 Spring Tools 一直占用jar,导致无法删除jar包
- gdb工作原理和内核实现
- BaseAdapter中怎么使用Application全局变量
- 2016秋招笔试面试题一:Java及基础部分