问题描述:
测试requests库,抓了一张百度的logo,在文件写入的时候报了权限不够的错
import requests
response = requests.get('https://www.baidu.com/img/bd_logo1.png')
print(response.content)
with open('C:/baidu.png', 'wb') as f:
f.write(response.content)
f.close()
Traceback (most recent call last):
File "D:/PycharmProjects/untitled/test.py", line 42, in <module>
with open('C:/baidu.png', 'wb') as f:
PermissionError: [Errno 13] Permission denied: 'C:/baidu.png'
解决方法:
with open('baidu.png', 'wb') as f:
f.write(response.content)
f.close()
with open('D:/baidu.png', 'wb') as f:
f.write(response.content)
f.close()
还不快抢沙发