downloading images

PHOTO EMBED

Wed Apr 12 2023 15:20:47 GMT+0000 (Coordinated Universal Time)

Saved by @adebola

image_url= soup.find('img')["src"]

#using square brackets with a tag will fetch whatever attribute of such tag in the square brackets.

image= requests.get("http://adebola.pythonanywhere.com"+'/'+ image_url).content

#I had to put the main URL first because it is not an online image, it is a statically loaded image.

with open("first_image.jpeg", "wb") as img:

img.write(image)

#this creates the file name and writes the byte representation of the image found.

with open("first_image.jpeg", "rb") as img:

image= img.read()

print(image)

#this is to display the bytecode that was written and to confirm that our file was saved successfully
content_copyCOPY