使用requests 库爬取百度图片

import requests
import os
url='   '

root ='   '
path=root+'  .jpg'
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()
           
    else :
        print("all ok")
except:
    print("no")

官方文档

发布了17 篇原创文章 · 获赞 13 · 访问量 8987

猜你喜欢

转载自blog.csdn.net/weixin_44724691/article/details/105277846