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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter