pyhton 爬取某张图片

版权声明: https://blog.csdn.net/lyw_321/article/details/80016563

执行成功之后,会在F盘pics文件夹下有一张名为 20170211061910157 的图片

import requests
import os
url="http://image.nationalgeographic.com.cn/2017/0211/20170211061910157.jpg"
root="F:pics//"
path=root+url.split('/')[-1]
try:
    if not os.path.exists(root):
        os.mkdir(root)
    if not os.path.exists(path):
        r=requests.get(url)
        with open(path,'wb') as f:
            f.write(r.content)
            f.close()
            print("ok")
    else:
        print("yicunzai")
except:
    print("shibai")
        




猜你喜欢

转载自blog.csdn.net/lyw_321/article/details/80016563
今日推荐