# -*- coding:utf-8 -*-
import urllib
import string
def hook(a, b, c):
‘‘‘回调函数
@a: 已经下载的数据块
@b: 数据块的大小
@c: 远程文件的大小
‘‘‘
per = 100.0 * a * b / c
if per > 100:
per = 100
print ‘%.2f%%‘ % per
url = ‘http://www.****.net‘
local = ‘d://****.html‘
#urllib.urlretrieve(url, local, hook)
#urllib.urlcleanup()
# quote unquote
data = ‘name = a+3‘
data1 = urllib.quote(data)
print data1
print urllib.unquote(data1)
# quote_plus unquote_plus
data2 = urllib.quote_plus(data)
print data2
print urllib.unquote_plus(data2)
# urlencode()
data3 = urllib.urlencode({‘name‘:‘huang‘,‘age‘:20})
print data3
data4 = urllib.pathname2url(r‘d:/a/b/c/23.php‘)
print data4
print urllib.url2pathname(data4)
s = ‘huang‘
print string.lowercase
print dir(str)
string.Formatter.format(s)
python实例,布布扣,bubuko.com
python实例