The webpage example is: link
The goal is to download all of the images, but once for each one of them.
Here's the code I'm using:
links = []
wait = WebDriverWait(driver, 5)
all_images = wait.until(
EC.presence_of_all_elements_located((By.XPATH, "//div[contains(@class,'swiper-button-next swiper-button-white')]")))
for image in all_images:
a = image.get_attribute('style')
b = a.split("(")[1].split(")")[0].replace('"', '')
links.append(b)
all_images = wait.until(
EC.presence_of_all_elements_located((By.XPATH, "//div[contains(@class,'swiper-slide swiper-slide-visible swiper-slide-active swiper-slide-thumb-active')]")))
for image in all_images:
a = image.get_attribute('style')
b = a.split("(")[1].split(")")[0].replace('"', '')
links.append(b)
all_images = wait.until(
EC.presence_of_all_elements_located((By.XPATH, "//div[contains(@class,'swiper-slide swiper-slide-visible')]")))
for image in all_images:
a = image.get_attribute('style')
b = a.split("(")[1].split(")")[0].replace('"', '')
links.append(b)
index = 1
for i in range(len(links)//2 + 1):
with open(title.replace(' ', '-') + str(index) + '.jpg', 'wb') as file:
im = requests.get(links[i])
file.write(im.content)
print('Saving image.. ', title + str(index))
index += 1
The problem is, it saves repetitive images, and doesn't save some of them, I don't know where I went wrong.