Manga (Japanese comics) aren't available in pdf but in raw images, so I created a tool that would automatically download the photos.
Here's my code
import requests
import urllib.request
from bs4 import BeautifulSoup
responsePage = input("Enter URL: ")
response = requests.get(responsePage)
soup = BeautifulSoup(response.text, 'html.parser')
images = soup.findAll('img')
image_name = 0
for img in images[1:-1]:
image_name += 1
url = img['src']
full_name = str(image_name) + '.jpg'
print(response.headers)
resource_image = urllib.request.urlretrieve(url, full_name)
print(full_name + " Saved!")
The error I receive is:
urllib.error.HTTPError: HTTP Error 403: Forbidden
Any suggestions on how I can solve this problem? Help would be appreciated.
import requests
from bs4 import BeautifulSoup
import os
def download_image(url, path):
r = requests.get(url, stream=True)
if r.status_code == 200:
with open(path, 'wb') as f:
for chunk in r:
f.write(chunk)
URL = "https://manganelo.com/chapter/read_detective_conan_manga_online_free/chapter_10"
r = requests.get(URL)
soup = BeautifulSoup(r.text, 'html.parser')
images = soup.findAll('img')
for i in images:
url = i.attrs["src"]
os.makedirs(url.split('/')[-2], exist_ok=True)
download_image(url, os.path.join(url.split('/')[-2], url.split('/')[-1]))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments