I am downloading a file like so
downloadurl = "www.site.com/my_link"
urllib.request.urlretrieve(downloadurl, "/root/watch/0.txt")
However, I would like to download the file to a specific folder but have the file name be generated from the link (like the file name if I entered the download url in a web browser and the file name is automatically generated. Is this possible in python?
I cannot parse the link as the file name is not present in the link.
如果downloadurl
在最后一个url部分包含文件名,你可以这样做:
urllib.request.urlretrieve(downloadurl, "/root/watch/" + downloadurl[downloadurl.rindex("/") + 1:])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.