Python 3.x Download a file from the internet in python?
Python 3.x Download a file from the internet in python?,python-3.x,python-requests,filepath,Python 3.x,Python Requests,Filepath,Any inputs?
You are opening a requests object not a file path
file_url = requests.get(downloadUrl) with open(file_url, 'w+') as f:
You would need to open a filepath on disk somewhere and write to that
See Using the request Module on https://stackabuse.com/download-files-with-python/
EDIT: From comments on post
In : link = "https://www.annualreports.com/HostedData/AnnualReportArchive/3/NASDAQ_QFIN_2018.pdf" In : import requests In : file_url = requests.get(link) In : with open('/tmp/NASDAQ_QFIN_2018.pdf', 'wb') as f: ...: f.write(file_url.content) ...: In : ls -al /tmp/NASDAQ_QFIN_2018.pdf -rw-r--r-- 1 ME wheel 1796199 9 Apr 15:21 /tmp/NASDAQ_QFIN_2018.pdf
#2This looks quite similar to this other recent question.
#3@GinoMempin yeah! but it is not answered, so I still need an answer sir, Thank you
#4i think you mean
with open(filepath, 'w+') as f:as
file_urlcontains response and not the url of the file you want to create.
#5Thank you for clarification, but I'm getting a PermissionError: [Errno 13] Error after adding with open(filepath, 'w+') as f:
#6That is because you are trying to open a Directory not a file you would need to download to
#7Okay. I have done it. Now I can enter a path as
userinputrefer to edited codes above. the script will download the file in the specified path, but the problem the downloaded file will be empty.
#8What is an example URL you are trying to download?