python通过http下载文件的方法详解

发布时间:2020-09-10 14:22:19 作者:bainianminguo
来源:脚本之家 阅读:331

1、通过requests.get方法

r = requests.get("http://200.20.3.20:8080/job/Compile/job/aaa/496/artifact/bbb.iso")
 
with open(os.path.join(os.path.dirname(os.path.abspath("__file__")),"bbb.iso"),"wb") as f:
  f.write(r.content)

2、urllib2方法

import urllib2
print "downloading with urllib2"
url = '"http://200.21.1.22:8080/job/Compile/job/aaa/496/artifact/bbb.iso"'
f = urllib2.urlopen(url)
data = f.read()
with open(os.path.join(os.path.dirname(os.path.abspath("__file__")),"bbb.iso"),"wb") as f:
  f.write(data)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

推荐阅读:
  1. http基础性问题,http详解
  2. 通过字符串导入 Python 模块的方法详解

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python http 下载

上一篇:python叫胶水语言的原因有哪些

下一篇:web.xml有哪些作用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》