码迷,mamicode.com
首页 > 编程语言 > 详细

python3----练习题(....)

时间:2018-01-27 11:22:34      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:split   not   with open   cep   url   else   close   保存   style   

 1 def save_file():
 2     url = http://css.8684.cn/citys/images/line/45.jpg
 3     root = rd:/pics/
 4     path = root + url.split(/)[-1]
 5     try:
 6         if not os.path.exists(root):
 7             os.mkdir(root)
 8         if not os.path.exists(path):
 9             r = requests.get(url)
10             with open(path, wb) as f:
11                 f.write(r.content)
12                 f.close()
13                 print("文件保存成功")
14         else:
15             print("文件已存在")
16     except:
17         print("爬取失败")

 

python3----练习题(....)

标签:split   not   with open   cep   url   else   close   保存   style   

原文地址:https://www.cnblogs.com/jonm/p/8362217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!