Mirek
Mirek

Reputation: 31

Is it possible to download image from website via Selenium (Python) in case is generated dynamically from server?

I found out in Web Inspector tool image on one site (domain is just for example) https://somesite.com/asd/photo.pl?num=10 which is not part of website but is probably generated dynamically from server.
I would like to ask if is possible to download it via selenium in python.
I tried this but it does not works. I think it is not possible by this way due to server site like I meantioned.

from selenium import webdriver

import urllib.request
import shutil
import time
import requests

driver = webdriver.Firefox()

driver.get("https://somesite.com/")

img = driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/a/img')
img_url = img.get_attribute('src')
response = requests.get(img_url)

with open("saved_image.jpg", "wb") as file:
    file.write(response.content)

Upvotes: 0

Views: 139

Answers (0)

Related Questions