2016-09-06 67 views
-1

我想在Python中構建一個刮板,只想下載播客的新劇集。問題是,我不知道下載文件之後文件名是什麼。有沒有辦法在下載之前獲取文件名?下載前獲取文件名

def download(path, fileName): 
    if(not os.path.exists(fileName)): 
     wget.download(path) 
+1

什麼是網站獲得的文件名? –

+0

thetalkingmachines.com – Char

回答

-1

我猜想,podcast的網址會將您重定向到另一個網址。然後你可以使用requests得到最終的網址

import requests 
final_url = requests.head(url_to_podcast, allow_redirects=True).url 

,然後從最終網址

filename = final_url.split('/')[-1]