diff --git a/image_downloader/README.md b/image_downloader/README.md new file mode 100644 index 0000000..97e9476 --- /dev/null +++ b/image_downloader/README.md @@ -0,0 +1,3 @@ +# Image Donwloader + +With this script you can download all images off a webite. diff --git a/image_downloader/image_downloader.py b/image_downloader/image_downloader.py new file mode 100644 index 0000000..baad155 --- /dev/null +++ b/image_downloader/image_downloader.py @@ -0,0 +1,24 @@ +"""This script loads all images of a website.""" + +import mimetypes +import requests +from bs4 import BeautifulSoup + +while True: + try: + url = input("Your Website:") + website = requests.get(url) + break + except: + print("I can't open the website!") +html = BeautifulSoup(website.text, "html.parser") +images = html.find_all("img") + +def download(url, filename): + file_url = requests.get(url) + file_extension = mimetypes.guess_extension(file_url.headers['content-type']) + with open(filename+file_extension, 'wb') as file: + file.write(file_url.content) + +for index, image in enumerate(images): + download(image["src"], "image{index}".format(index=index))