Download pdf using urllib?
问题 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? 回答1: Here is an example that works: import urllib2 def