python3 爬虫 urlretrieve
2016-08-20 19:55
393 查看
网上的Python3 爬虫教程很少,自己就写了个小例子。
import re import urllib.request ###result yes # version 3.5 def Schedule(a,b,c): ''' a:已经下载的数据块 b:数据库块的大小 c:远程文件的大小 ''' per = 100.0 * a * b / c if per>100: per = 100 print('完成!') print('%.2f%%' % per) def getHtml(url): page = urllib.request.urlopen(url) html = page.read() return html def getImg(html): html = html.decode('utf-8') reg = r'src="(.*?\.jpg)" width' imgre = re.compile(reg) imglist = imgre.findall(html) #print(imglist) x = 0 for imgurl in imglist: urllib.request.urlretrieve(imgurl,'e:\\test\\%s.jpg' % x,Schedule)#是不是Python3.X中把这个也改变了? x += 1 html = getHtml('http://tieba.baidu.com/p/741081023') print(getImg(html))
相关文章推荐
- 萌新的Python学习日记 - 爬虫无影 - 使用BeautifulSoup + urlretrieve 抓取并保存图片:weheartit
- Python爬虫关于urlretrieve()函数的使用笔记
- Python 简单爬虫程序 以及 urllib.urlretrieve()方法 改变文件存放文件位置
- 【Python3 爬虫】04_urllib.request.urlretrieve
- Python urllib模块urlopen()【打开网站,写入本地文件】与urlretrieve()【直接下载网站文件到本地】
- [python]解决urllib.urlretrieve()下载不完全的问题
- (转)Python urllib模块urlopen()与urlretrieve()详解
- Python urllib模块urlopen()与urlretrieve()详解
- python使用urllib.urlretrieve时出现“IOError:[Errno 2] No such file or directory”解决办法
- Python 网络爬虫 009 (编程) 通过正则表达式来获取一个网页中的所有的URL链接,并下载这些URL链接的源代码
- python爬虫:抓取乌云厂商url
- 用python爬取图片之urlretrieve的用法
- Python urllib模块urlopen()与urlretrieve()详解
- [Python]网络爬虫1:抓取网页的含义和URL基本构成 笔记
- python urlretrieve
- python爬虫url带中文解决方案之一
- python爬虫中对含中文的url处理
- python网络爬虫(一):网络爬虫科普与URL含义
- python抓取搜索到的url,小型爬虫
- 【Python学习】Python写爬虫时用到的相对路径和绝对路径--urljoin