方法一:
import urllib
import urllib2
import requests
print "downloading with urllib"
url = 'http://www.pythontab.com/test/demo.zip'
print "downloading with urllib"
urllib.urlretrieve(url, "demo.zip")
方法二:
import urllib2
print "downloading with urllib2"
url = 'http://www.pythontab.com/test/demo.zip'
f = urllib2.urlopen(url)
data = f.read()
with open("demo2.zip", "wb") as code:
code.write(data)
方法三:
import requests
print "downloading with requests"
url = 'http://www.pythontab.com/test/demo.zip'
r = requests.get(url)
with open("demo3.zip", "wb") as code:
code.write(r.content)
import urllib
import urllib2
import requests
print "downloading with urllib"
url = 'http://www.pythontab.com/test/demo.zip'
print "downloading with urllib"
urllib.urlretrieve(url, "demo.zip")
import urllib2
print "downloading with urllib2"
url = 'http://www.pythontab.com/test/demo.zip'
f = urllib2.urlopen(url)
data = f.read()
with open("demo2.zip", "wb") as code:
code.write(data)
import requests
print "downloading with requests"
url = 'http://www.pythontab.com/test/demo.zip'
r = requests.get(url)
with open("demo3.zip", "wb") as code:
code.write(r.content)