Incorrect Image Download Issue

28 views Asked by At

This is my code:

 # Extract the images
            images = product_soup.find_all('div', class_='woocommerce-product-gallery__image')
            for i, image in enumerate(images):
                img_src = image.find('img')['src']
                print(img_src)

                # Download the image
                img_r = r.get(img_src, stream=True)

                # Save the image with the title and a number as the file name
                with open(f'{title}_{i}.jpg', 'wb') as f:
                    for chunk in img_r:
                        f.write(chunk)

this is the result: enter image description here

the problem is that some image are not downloading properly: enter image description here

What is the reason that this is happening and how can I fix that? It looks like the image is a WEBP file but if I save it manually as jpg it save fine.

0

There are 0 answers