python下载文件

第一种:用 
 urlopen()方法 
 

import urllib
url = "http://www.baidu.com/"
#urlopen()
sock = urllib.urlopen(url)
htmlCode = sock.read()
sock.close
fp = open("e:/1.html","wb")
fp.write(htmlCode)
fp.close
第二种:用 urlretrieve()方法

urllib.urlretrieve(url, 'e:/2.html')




你可能感兴趣的:(python下载文件)