网络图片获取代码

2018-11-03  本文已影响0人  Destiny_0ea2

import requests

import os

url="https://p1.ssl.qhimg.com/t015e3351debe4158e3.jpg"

root="F://picture//"

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("success to save document")

    else:

        print("document has saved")

except:

    print("spyder wrong")

上一篇 下一篇

猜你喜欢

热点阅读