FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题
最近在学习爬虫,想爬一些图片并保存到本地,但是在下载图片的时候遇到了各种问题,这里就说一下最后解决好了的问题。
(代码就不粘贴出来了哈)
按理来说,这个代码能够正常运行,因为我是跟着一个博主学的,可能是因为权限问题吧,我试过改过别的盘来存储运行,但是还是一样的结果。
运行之后出现这样的错误:
意思就是存不了。
解决方法:
法一:
1.导入os库
2.把要存放的路径复制一下,加上显示的格式
3.用os.path.expanduser()函数
4.正确找到路径
5.运行成功
法二:
还有一种方法就是在你的.py文件下建立一个独立的文件夹img存你下载下来的照片
然后使用'./img/’保存到文件夹里面with open('./img/' + str(count) + '.jpg', mode="wb") as file:
运行成功:
以上是本人的一些小经验,如有不足,欢迎指正。
相关文章:
- [Errno 2] No such file or directory 2022-12-23
- Python中的打开文件错误,FileNotFoundError: [Errno 2] No such file or directory:(转载) 2022-12-23
- pycurl安装失败报FileNotFoundError: [Errno 2] No such file or directory: 'curl-config' 2022-12-23
- Yum:[Errno 5] [Errno 2] No such file or directory 2021-07-04
- Python中的用open打开文件错误,FileNotFoundError: [Errno 2] No such file or directory: 2021-10-29
- FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\86188\\data\\rt-polaritydata\\rt 2021-05-04
- IOError: [Errno 2] No such file or directory 2021-11-20
- Pycharm踩坑 FileNotFoundError: [Errno 2] No such file or directory: '../data/users.txt' 目录结构 2021-08-02