python 保存文件 ,报错‘[Errno 2] No such file or directory:

本人刚刚接触python,爬了个图片网站,最后保存遇见了问题
报错’‘[Errno 2] No such file or directory: '动漫/210813/224838-16288661183b3f.jpg'
把保存图片的代码注释掉,选择在动漫文件夹里面添加文本就不报错
所以我确定我的文件路径是没有问题的

import requests
from bs4 import BeautifulSoup
import os

print(os.getcwd())
url = 'https://pic.netbian.com/4kdongman/'
resp = requests.get(url)
resp.encoding = 'gbk'

bs = BeautifulSoup(resp.text, 'html.parser')
a_list = bs.find('div', class_='slist').find_all('a')
shild_urls = []
for a in a_list:
    a = a.get('href')
    shild_url = url.split('/4kdongman/')[0] + a
    shild_urls.append(shild_url)


src_list = []
for b in shild_urls:
    resp = requests.get(b)
    resp.encoding = 'gbk'
    bs = BeautifulSoup(resp.text, 'html.parser')
    img = bs.find('div', class_='photo-pic').find('img')
    src = url.split('/4kdongman/')[0] + img.get('src')
    src_list.append(src)
for src in src_list:
    name = src.split('allimg/')[1]
    with open(f'动漫/{name}', mode='wb') as f:
        resp = requests.get(src).content
        f.write(resp)

import requests
from bs4 import BeautifulSoup
import os

print(os.getcwd())
url = 'https://pic.netbian.com/4kdongman/'
resp = requests.get(url)
resp.encoding = 'gbk'

bs = BeautifulSoup(resp.text, 'html.parser')
a_list = bs.find('div', class_='slist').find_all('a')
shild_urls = []
for a in a_list:
    a = a.get('href')
    shild_url = url.split('/4kdongman/')[0] + a
    shild_urls.append(shild_url)


src_list = []
for b in shild_urls:
    resp = requests.get(b)
    resp.encoding = 'gbk'
    bs = BeautifulSoup(resp.text, 'html.parser')
    img = bs.find('div', class_='photo-pic').find('img')
    src = url.split('/4kdongman/')[0] + img.get('src')
    src_list.append(src)
# for src in src_list:
#     name = src.split('allimg/')[1]
#     with open(f'动漫/{name}', mode='wb') as f:
#         resp = requests.get(src).content
#         f.write(resp)

f =open('动漫/03.text', mode='w')
f.write('123456')


img

F盘里如果没有动漫这个文件夹就会报错

学爬虫可以关注我哦。不定期逆向分享,你这个文件夹没有创建,