簡體   English   中英

我無法讓 tqdm 的下載進度條顯示進度

[英]I can't make the download progress bar from tqdm to show the progress

我想用 tqdm 添加一個下載進度條。 問題是它向我展示了這一點:

0%|                                                                           | 0/11535.92578125 [00:00<?, ?KB/s]

它下載文件而不顯示任何進度。 這是我的代碼:

s = requests.Session()
r = s.post(url, login_data)
response = s.get(link_to_pdf, stream=True)
total_size = int(response.headers['content-length'])
# download the pdf
print(pdf_filename)
with open(pdf_filename + '.pdf', 'wb') as f:
    for data in tqdm(iterable=response.iter_content(chunk_size=chunk_size), total=total_size/chunk_size, unit='KB'):
        f.write(response.content)

你沒有寫你寫請求的數據 1 次而不是塊,jsut 替換你從 tqdm 獲得的數據縫隙中寫入文件的 response.content

  with open(pdf_filename + '.pdf', 'wb') as f:
    for data in tqdm(iterable=response.iter_content(chunk_size=chunk_size), total=total_size / chunk_size, unit='KB'):
        f.write(data)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM