Created
May 1, 2013 20:20
-
-
Save akleemans/5498050 to your computer and use it in GitHub Desktop.
Simple download of a PDF file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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