Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created March 5, 2020 08:27
Show Gist options
  • Save e96031413/82fbf2ad7d1d2ba1f31c8517f8c610d5 to your computer and use it in GitHub Desktop.
Save e96031413/82fbf2ad7d1d2ba1f31c8517f8c610d5 to your computer and use it in GitHub Desktop.
使用tqdm進度條、使用requests下載、使用split()方法進行檔名建立的範例
from tqdm import tqdm
import requests as req
url = "https://abc.com.tw/123.jpg"
def download(url):
filename = url.split('/')[-1] #可以觀察其filename的寫法做為參考
r = req.get(url, stream=True)
with open(filename, 'wb') as f:
for data in tqdm(r.iter_content(1024)):
f.write(data)
return filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment