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:

运行成功:





以上是本人的一些小经验,如有不足,欢迎指正。

FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决的更多相关文章

  1. 关于python中的 “ FileNotFoundError: [Errno 2] No such file or directory: '……'问题 ”

    今天在学python时,在模仿一个为图片加上图标并移动到指定文件夹的程序时遇到“FileNotFoundError: [Errno 2] No such file or directory: '152 ...

  2. python文件操作的坑( FileNotFoundError: [Errno 2] No such file or directory...)

    环境:Windows8.1, Python3.6  pycharm community 2017   c盘下有一个配置文件:setup   with open('c:\\setup','r') as ...

  3. 关于JPype报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误的解决

    部署到线上的项目正常运行一年,今天早上突然报FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/jvm'错误. JPyp ...

  4. Python中的用open打开文件错误,FileNotFoundError: [Errno 2] No such file or directory:

    学习python的文件处理,刚开始打开文件,代码如下 f = open('test_file.txt', 'r', encoding='UTF-8')RES = f.readlines()print( ...

  5. 对于python中“FileNotFoundError: [Errno 2] No such file or directory”的解决办法

    在我们使用vscode运行Python代码时遇到的情况 一.出现原因:这里是由于Vscode中,python里的路径是相对与工作目录来进行定位的.所以在多级目录情况下,若不设置绝对路径,往往找不到相应 ...

  6. FileNotFoundError: [Errno 2] No such file or directory的解决方法

    1.获取当前文件所在路径 basedir = os.path.dirname(__file__) print("basedir:" + basedir) 2.将路径进行拼接 upl ...

  7. python3 使用selenium +webdriver打开chrome失败,报错:FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

    提示chrome driver没有放置在正确的路径下 解决方法: 1.chromedriver与chrome各版本及下载地址 驱动的下载地址如下: http://chromedriver.storag ...

  8. RHEL 5.7 Yum配置本地源[Errno 2] No such file or directory

    在Red Hat Enterprise Linux Server release 5.7 上配置YUM本地源时,遇到了"Errno 5] OSError: [Errno 2] No such ...

  9. VSCode python 遇到的问题:vscode can't open file '<unprintable file name>': [Errno 2] No such file or directory

    代码很简单,就两行: import pandas as pd import netCDF4 as nc dataset = nc.Dataset('20150101.nc') 环境:在VSCode中左 ...

随机推荐

  1. BGP的四类属性详解

    BGP的四类属性 公认必遵(Well-known mandatory) 要求所有运行BGP协议的设备都必须能识别,且在更新消息中必须包含. Origin(起源) 属性 用来标识路由信息的来源. 如果路 ...

  2. 论文翻译:2021_Acoustic Echo Cancellation with Cross-Domain Learning

    论文地址:https://graz.pure.elsevier.com/en/publications/acoustic-echo-cancellation-with-cross-domain-lea ...

  3. Linux(centos7)安装RabbitMQ

    由于RabbitMQ是由Erlang语言开发的,所以我们需要体检安装erlang语言的环境 下载这三个安装包:https://www.aliyundrive.com/s/4AxfTepHjMD 执行安 ...

  4. Arthas之类操作

    Arthas之类操作 1. classLoader 查询当前JVM中存在的classloader classloader name numberOfInstances loadedCountTotal ...

  5. 什么是tar 命令?

    用来压缩和解压文件.tar 本身不具有压缩功能,只具有打包功能,有关压缩及解压是调用其它的功能来完成.弄清两个概念:打包和压缩.打包是指将一大堆文件或目录变成一个总的文件:压缩则是将一个大的文件通过一 ...

  6. chrome删除保存的密码

    chrome删除保存的密码 关于谷歌密码管理器 该管理器是将我们的密码管理在google的账号中,当然,谷歌是说用了加密技术保存的,不会存储明文. https://passwords.google.c ...

  7. Kafka 的高可靠性是怎么实现的?

    可以参见我这篇文章:Kafka 是如何保证数据可靠性和一致性

  8. Springmvc入门基础(六) ---拦截器应用demo

    1.拦截器定义 Spring Web MVC 的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理. 2.拦截器demo demo需求: 拦截用户请求,判断用 ...

  9. @Component, @Controller, @Repository, @Service 有何区别?

    @Component :这将 java 类标记为 bean.它是任何 Spring 管理组件的通 用构造型.spring 的组件扫描机制现在可以将其拾取并将其拉入应用程序环境 中. @Controll ...

  10. 【Flutter】Flutter C/C++ 插件的开发 (支持 windows、macos、ios、android )

    一个各平台调用 C/C++ 源码的例子,如何共享代码,配置相关的编译 官方的例子:https://docs.flutter.dev/development/platform-integration/c ...