使用Python的requests库分块下载大文件显示百分百

前提是响应头里需要包含content-length


url = "http://xxx.com/bigfile.txt" file_name = "file/file.txt" count = 0 with closing(requests.get(url, stream=True)) as res: chunk_size = 10240 # 每次请求的块大小 content_size = int(res.headers['content-length']) # 文件总大小 with open(file_name = "", "wb") as file: for data in res.iter_content(chunk_size=chunk_size): count += 1 current = len(data) * count / 1024 / 1024 total = content_size / 1024 / 1024 pring("total: %.2f MB current:%.2f MB percent:%.2f" % (total, current, current/total*100)) file.write(data)

депутат лобановскийместоположение телефона по номеру онлайннакрутить людей в группу вкодноклассникиодноклассники вход на сайтдоставка грузов комролокасети

发表评论

[/0o0] [..^v^..] [0_0] [T.T] [=3-❤] [❤.❤] [^v^] [-.0] [!- -] [=x=] [→_→] [><] 更多 »
昵称

抢沙发~