Created
March 5, 2020 08:27
-
-
Save e96031413/82fbf2ad7d1d2ba1f31c8517f8c610d5 to your computer and use it in GitHub Desktop.
使用tqdm進度條、使用requests下載、使用split()方法進行檔名建立的範例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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