Skip to content

Commit

Permalink
Sat, Aug 3, 2024, 8:36 AM +03:00
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdoullahBougataya committed Aug 3, 2024
1 parent 197483c commit f2998ff
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions images_scrapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import requests
from bs4 import BeautifulSoup
import scrapper
import time
import os

def download_image(image_url, file_dir):
response = requests.get(image_url)

if response.status_code == 200:
directory = os.path.dirname(file_dir)
if not os.path.exists(directory):
os.makedirs(directory)

with open(file_dir, "wb") as fp:
fp.write(response.content)
print("Image downloaded successfully.")
else:
print(f"Failed to download the image. Status code: {response.status_code}")

titles, engines = scrapper()
for engine in engines:
Expand All @@ -26,4 +40,4 @@
if soup.find("table", {"class" : "infobox"}).find("td", {"class": "infobox-image"}).find("img").get("srcset"):
if len(soup.find("table", {"class" : "infobox"}).find("td", {"class": "infobox-image"}).find("img").get("srcset").split()) > 2:
pic_url = "https:" + str(soup.find("table", {"class" : "infobox"}).find("td", {"class": "infobox-image"}).find("img").get("srcset").split()[2])
print(pic_url)
download_image(pic_url, f"/images/{engine_name}.jpg")

0 comments on commit f2998ff

Please sign in to comment.