下载前获取文件名

2024-05-19 02:13:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用python构建一个scraper,只想下载podcast的新剧集。问题是我不知道文件名,直到文件下载后。有没有办法在下载前获取文件名?在

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

Tags: 文件pathifos文件名downloaddefexists
1条回答
网友
1楼 · 发布于 2024-05-19 02:13:48

我猜podcast的url会把你重定向到另一个url。然后可以使用requests来获得最终的url

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

然后从最终的url获取文件名

^{pr2}$

相关问题 更多 >

    热门问题