爬中国地理单张图片并保存到本地

import requests

path = "C:\\Users\\QAQ\\Desktop/abc.jpg"
url = "http://img0.dili360.com/pic/2020/07/13/5f0bc42e47cbf0c15485657.jpg@!rw9"
r = requests.get(url)
print(f'{r.status_code}')
with open(path, 'wb') as f:
    print(f.write(r.content))
f.close()

原名保存功能实现:

import requests
import os
url = "http://img0.dili360.com/pic/2020/07/13/5f0bc42e47cbf0c15485657.jpg@!rw9"
root = "C:\\Users\\QAQ\\Desktop/"
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:
            print(f.write(r.content))
            f.close()
            print('文件保存成功')
    else:
        print('文件已存在')
except:
    print('爬取失败')

https://www.icourse163.org/learn/BIT-1001870001?tid=1461055451#/learn/content?type=detail&id=1237343299&cid=1257258713

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页