python url 下载并保存

Posted gloria11

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python url 下载并保存相关的知识,希望对你有一定的参考价值。

方法一:用urllib

import json
import urllib
url_model=‘{"version":"2","url":"http://20180803.oss-cn-shanghai.aliyuncs.com/video/frozen_inference_graph_2.pb","instruction":"8967"}‘
url_model_txt=json.loads(url_model)
url = url_model_txt[‘url‘]

print "downloading with urllib"
urllib.urlretrieve(url, "./3.pb")
方法二:

import json

import urllib2

url_model=‘{"version":"2","url":"http://20180803.oss-cn-shanghai.aliyuncs.com/video/frozen_inference_graph_2.pb","instruction":"8967"}‘
url_model_txt=json.loads(url_model)
url = url_model_txt[‘url‘]

f = urllib2.urlopen(url)

data = f.read()
with open("./2/frozen_inference_graph.pb", "wb") as code:
    code.write(data)

方法三:

url_model=‘{"version":"2","url":"http://20180803.oss-cn-shanghai.aliyuncs.com/video/frozen_inference_graph_2.pb","instruction":"8967"}‘
url_model_txt=json.loads(url_model)
url = url_model_txt[‘url‘]

f = requests.get(url)

with open("./2.pb","wb") as code:

    code.write(f.content)

 

 














以上是关于python url 下载并保存的主要内容,如果未能解决你的问题,请参考以下文章

python url 下载并保存

Python爬虫获取图片并下载保存至本地的实例

#VSCode保存插件配置并使用 gist 管理代码片段

VSCode自定义代码片段3——url大全

VSCode自定义代码片段3——url大全

VSCode自定义代码片段3——url大全