python中下载文件常用的几个模块有urllib,urllib2,requests,方法也很简单,代码如下:
002pc.com从python 获取机器snpython下载文件的几种常用方法分析来看,对python 获取机器snpython下载文件的几种常用方法的结果。# Python 2 code
import urllib
import urllib2
import requests
url = 'http://192.168.1.100/test.zip'
print "downloading with urllib"
urllib.urlretrieve(url, "code.zip")
print "downloading with urllib2"
f = urllib2.urlopen(url)
data = f.read()
with open("code2.zip", "wb") as code:
code.write(data)
print "downloading with requests"
r = requests.get(url)
with open("code3.zip", "wb") as code:
code.write(r.content)具体详情可参见:http://www.blog.pythonlibrary.org/2012/06/07/python-101-how-to-download-a-file/
本文出自 “王伟” 博客,请务必保留此出处http://wangwei007.blog.51cto.com/68019/1351429
更多:python 获取机器snpython下载文件的几种常用方法
https://www.002pc.comhttps://www.002pc.com/python/1547.html
你可能感兴趣的python,几种,下载,常用,文件,方法
No alive nodes found in your cluster
0踩
赏
0 赞