0

I'm trying to make an automated program that downloads a certain file from a link. Problem is, I don't know what this file will be called. Its always a .zip so for example: filename_4213432.zip . The link does not include this filename in it. It looks something like this https://link.com/api/download/433265902. Therefore its impossible to get the filename trough the link. Is there a way to fetch this name and download it?

print("link:")
url = input("> ")

request = requests.get(url, allow_redirects=True)

I'm stuck at this point because I don't know what to put in my open() now.

Mark dG
  • 321
  • 1
  • 13
  • Does the filename matter? You could take the ID at the end of the url and just name it `{id}.zip` – OneCricketeer Feb 02 '21 at 21:57
  • [This answer](https://stackoverflow.com/a/35220413/2378643) on using the `Content-Disposition` header may answer your question. – Anon Coward Feb 02 '21 at 21:59
  • @OneCricketeer they don't care about the filename, they need a way to get the file's direct link so they can download it in the first place. Like with [this question](https://stackoverflow.com/questions/39551320/python-download-video-from-indirect-url). – Random Davis Feb 02 '21 at 21:59
  • @OneCricketeer The numbers behind the link does not stand for an ID I think. – Mark dG Feb 02 '21 at 22:17
  • Doesn't matter what they stand for, my point was that you can use that part of the URL. Why do you need access to the actual filename when you can just save the response to your own file that you can use open() with? https://stackoverflow.com/questions/44699682/how-to-save-a-file-downloaded-from-requests-to-another-directory/44699728 – OneCricketeer Feb 03 '21 at 13:30

0 Answers0