I am trying to download a pdf file from a website using urllib. This is what i got so far:
import urllib
def download_file(download_url):
web_file = urllib.urlopen(download_url)
local_file = open('some_file.pdf', 'w')
local_file.write(web_file.read())
web_file.close()
local_file.close()
if __name__ == 'main':
download_file('http://www.example.com/some_file.pdf')
When i run this code, all I get is an empty pdf file. What am I doing wrong?
getcode()
). This might provide some clue. If all is OK at http-level, we have to look elsewhere. Have you tried to download a PDF from an other source? Could you provide the real URL of the PDF for testing purposes? – Instillation