From 800a4239ef7a0199ff8ce72148023fdc484bfa8c Mon Sep 17 00:00:00 2001 From: g1879 Date: Wed, 3 Jun 2020 10:26:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83download=E7=9A=84show=5Fmsg?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/session_page.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DrissionPage/session_page.py b/DrissionPage/session_page.py index 1b8c92d..8ff745d 100644 --- a/DrissionPage/session_page.py +++ b/DrissionPage/session_page.py @@ -149,6 +149,7 @@ class SessionPage(object): if show_msg: print_txt = file_full_name if file_name == file_full_name else f'{file_name} -> {file_full_name}' print(print_txt) + print(f'Downloading to: {goal_path}') # -------------------开始下载------------------- # 获取远程文件大小 file_size = int(r.headers['Content-Length']) if 'Content-Length' in r.headers else None @@ -158,12 +159,11 @@ class SessionPage(object): full_path = Path(f'{goal_path}\\{file_full_name}') try: with open(str(full_path), 'wb') as tmpFile: - print(f'Downloading to: {goal_path}') for chunk in r.iter_content(chunk_size=1024): if chunk: tmpFile.write(chunk) # 如表头有返回文件大小,显示进度 - if file_size: + if show_msg and file_size: downloaded_size += 1024 rate = downloaded_size / file_size if downloaded_size < file_size else 1 print('\r {:.0%} '.format(rate), end="")