I have a project at school with an e-commerce website that I need a large number of images to complete. So I consulted the code to download images from Youtube: John Watson Rooney But I was having problem downloading half of the image Url changed to 'data:image/gif;base64,R0lGODdhFQAXAPAAANba3wAAACwAAAAAFQAXAAACFISPqcvtD6OctNqLs968+w+GolUAADs=' so I can't continue downloading.
import requests
from bs4 import BeautifulSoup
import os
import base64
def imagedown(url, folder):
try:
os.mkdir(os.path.join(os.getcwd(), folder))
except:
pass
os.chdir(os.path.join(os.getcwd(), folder))
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
images = soup.find_all('img', class_='styles__productImage--3ZNPD')
for image in images:
name = image['alt']
link = image['src']
with open(name.replace('/', '').replace('?', '').replace('=', '').replace('|', '') + '.jpg', 'wb') as f:
im = requests.get(link)
f.write(im.content)
print('Writing: ', name)
imagedown('https://www.redbubble.com/shop/?gender=gender-men&iaCode=u-tees&page=2&query=dog&sortOrder=relevant&style=u-tee-regular-crew', 'Images')
I don't know where the error lies, please help me, thanks