Skip to content

Instantly share code, notes, and snippets.

@akleemans
Created May 1, 2013 20:20
Show Gist options
  • Save akleemans/5498050 to your computer and use it in GitHub Desktop.
Save akleemans/5498050 to your computer and use it in GitHub Desktop.
Simple download of a PDF file.
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Downloads a sample PDF file.
'''
import urllib2
def download(url):
print 'Starting download of', url
f = urllib2.urlopen(url)
data = f.read()
f.close()
print 'Finished downloading!'
return data
def main():
# url to PDF
url = 'http://files.swaroopch.com/python/byte_of_python.pdf'
# prepare output and call download()
f = open('byte_of_python.pdf', 'w')
data = download(url)
# write data and close
f.write(data)
f.close()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment