擅长:python、mysql、java
<p>我建议你试试<code>tqdm</code>[1],它很容易使用。
使用<code>requests</code>库[2]下载的示例代码:</p>
<pre class="lang-py prettyprint-override"><code>from tqdm import tqdm
import requests
url = "http://www.ovh.net/files/10Mb.dat" #big file test
# Streaming, so we can iterate over the response.
r = requests.get(url, stream=True)
# Total size in bytes.
total_size = int(r.headers.get('content-length', 0))
block_size = 1024 #1 Kibibyte
t=tqdm(total=total_size, unit='iB', unit_scale=True)
with open('test.dat', 'wb') as f:
for data in r.iter_content(block_size):
t.update(len(data))
f.write(data)
t.close()
if total_size != 0 and t.n != total_size:
print("ERROR, something went wrong")
</code></pre>
<p>[1]:<a href="https://github.com/tqdm/tqdm" rel="noreferrer">https://github.com/tqdm/tqdm</a><br/>
[2] :<a href="http://docs.python-requests.org/en/master/" rel="noreferrer">http://docs.python-requests.org/en/master/</a></p>