I started learning Python a couple weeks ago so I could make this project that saves all the images on multiple webpages. Everything works smoothly except the last lines, I get an error that says:
File "/Users/hitchhiker/Desktop/manga_yoinker/main.py", line 36, in <module> with open(filename, "wb") as file: FileNotFoundError: [Errno 2] No such file or directory: 'page/cropped-Jujutsu_kaisen-324x324-1.png'
Here is the code:
import os
import requests
from bs4 import BeautifulSoup
import shutil
link = "https://kaisenscans.com/chapter/jujutsu-kaisen-chapter-"
main_dir = os.path.join("/Volumes/flash", "main_folder")
os.mkdir(main_dir)
for chapter_number in range(1, 2):
chapter = link + str(chapter_number)
page = requests.get(chapter)
chname = "chapter"+str(chapter_number)
current_dir = "/Users/hitchhiker/Desktop/manga_yoinker/" + chname
destination = "/Volumes/flash/main_folder"
dire = os.mkdir(chname)
shutil.move(current_dir, main_dir)
soup = BeautifulSoup(page.content, "html.parser")
imgs = soup.find_all("img")
for img in imgs:
img_link = img.attrs.get("src")
image = requests.get(img_link).content
filename = "page" + img_link[img_link.rfind("/"):]
with open(filename, "wb") as file:
file.write(image)
I've searched on google for a solution but can't seem to find anything fitting my problem.