We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b04768c commit 36fe439Copy full SHA for 36fe439
2.download_with_process_bar.py
@@ -0,0 +1,31 @@
1
+# -*- coding: utf-8 -*-
2
+__author__ = "eason"
3
+import requests
4
+import os
5
+from tqdm import tqdm
6
+
7
8
+def download_file(url: str, save_path: str)->bool:
9
+ """
10
+ 下载文件并显示下载进度
11
+ :param url: 文件url
12
+ :param save_path: 保存路径
13
+ :return:
14
15
+ try:
16
+ local_filename = os.path.join(save_path, url.split('/')[-1])
17
+ r = requests.get(url, stream=True, timeout=60)
18
+ # Total size in bytes.
19
+ total_size = int(r.headers.get('content-length', 0))
20
+ # print url, total_size
21
+ with open(local_filename, 'wb') as f:
22
+ for chunk in tqdm(r.iter_content(), total=total_size, unit='B', unit_scale=True, desc=url.split('/')[-1],
23
+ leave=True, ncols=100):
24
+ f.write(chunk)
25
+ return True
26
+ except Exception as e:
27
+ print(repr(e))
28
+ return False
29
30
+if __name__ == "__main__":
31
+ download_file(url="https://dldir1.qq.com/qqfile/qq/TIM2.1.0/22747/TIM2.1.0.exe", save_path=r"C:\Users\eason\Desktop\test")
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments