python下载(http)文件并保存
import urllib2
request = urllib2.Request("http://www.appchina.com/market/r/639017/com.sohu.inputmethod.sogou.apk?channel=aplus.direct&p=aplus.index&uid=gAJ9cQFVC3ZlcmlmeV9jb2RlcQJVBGt1dWxxA3Mu1UNbT0ifMPYMADcmCTSaFDqhBcjWwME7w&page=appplus.category&ref=appplus.main")
response = urllib2.urlopen(request)
#test
file_size = int(response.headers['content-length'])
print file_zise
#test
with open("E:\\tmp\\tmp.apk", 'wb') as output:
??? while True:
??? ??? buffer = response.read(1024*256)
??? ??? if not buffer:
??? ??? ??? break
??? ??? output.write(buffer)
?
?