xtourmaline
xtourmaline

Reputation: 21

How do I download a high-quality photo when web scraping Google images?

so, i'm practicing web scraping in python3 and i'm just trying to download photos from google, but when i do, i get photos with low resolution.

import requests, webbrowser, bs4

# this code specifically looks for cats
res = requests.get(f"https://www.google.com/search?q=cat&tbm=isch")
res.raise_for_status()

soup = bs4.BeautifulSoup(res.text, "html.parser")

# gets the first 5 images from google images
searchImgs = soup.select("img")[:6]         

if searchImgs == []:
    sys.exit("No images found. Exiting..")
else:
    print("Images found. Opening browser..")

    # opens the browser with the images 
    for i in range(len(searchImgs)):
        webbrowser.open(searchImgs[i].get("src"))

this is because i am taking it from the image preview screen directly so the img is condensed. i would need to somehow open the image link and get it from there to get the full resolution but i don't particularly know how to and i don't know how i should go about it.

well first i tried to open the image link to download it from there but i couldn't find the image link. the only way i know how to get the image link is by right clicking and pressing on "open image in new tab" but i didn't know how to do that in python. i also couldn't find anything on the internet to help me, but that could also because i need to work on my searching skills.

Upvotes: 2

Views: 237

Answers (0)

Related Questions