print(str, end='\r')
# coding:utf-8
import requests
url = "http://wx4.sinaimg.cn/large/d030806aly1fq1vn8j0ajj21ho28bduy.jpg"
rsp = requests.head(url)
size = rsp.headers['Content-Length']
print("文件大小: %.2f MB" % (int(size)/1024/1024))
p = 0
rp = requests.get(url, stream=True)
with open('1.jpg', 'wb') as f:
for i in rp.iter_content(chunk_size=1024):
p += len(i)
f.write(i)
done = int(50 * p / int(size))
print("[%s%s] %s%%" % ('#' * done, '' * (50 - done), done+done), end='\r')
print("\nOK")
sys.stdout.write()
import sys
import requests
url = "http://wx4.sinaimg.cn/large/d030806aly1fq1vn8j0ajj21ho28bduy.jpg"
rsp = requests.head(url)
size = rsp.headers['Content-Length']
print("文件大小: %.2f MB" % (int(size)/1024/1024))
p = 0
rp = requests.get(url, stream=True)
with open('1.jpg', 'wb') as f:
for i in rp.iter_content(chunk_size=1024):
p += len(i)
f.write(i)
done = int(50 * p / int(size))
sys.stdout.write("\r[%s%s] %s%%" % ('#' * done, '' * (50 - done), done+done))
sys.stdout.flush()
print("\nOK")