[Python] Download images from encrypted-tbn0.gstatic.com using Python

Discussão em 'Python' iniciado por Stack, Maio 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am doing scraping of images from Google. I got image link in my script but this have this format

    https://encrypted-tbn0.gstatic.com/...hx1fG5kzUM5FGCSYmm2YBuLU3uSFFI5BviIWd6hrHbw&s

    I opened and here is the image but I cant use urllib.urlretrieve(imagenurl,imagen) for downdload.

    Someone know other way for download ? I am using python 2.7

    import requests
    from bs4 import BeautifulSoup
    import urllib

    def run():
    palabra ='pez'
    response = requests.get('https://www.google.com/search?q={}&hl=es&sxsrf=ALeKk00KoMQKffGLNWV5UEKbuPwpySPuig:1596391733831&source=lnms&tbm=isch&sa=X&ved=2ahUKEwiajd7Rjv3qAhXqTN8KHSINBkcQ_AUoAXoECBoQAw&biw=1262&bih=593'.format(palabra))
    soup = BeautifulSoup(response.content,'html.parser')
    imagenes = soup.find_all('img')

    for i in range(1,5):
    imagen_i = imagenes['src']
    imagen = imagen_i.split('/')[-1]
    print(imagen_i)
    #urllib.urlretrieve(imagen_i)


    if __name__ == '__main__':
    run()

    Continue reading...

Compartilhe esta Página