I'm using Python, and I'm trying to render web pages with Selenium and download all of their images. The method I've read about is to save the src
attribute URL values and then submit another HTTP request, like so:
import urllib.request
url = driver.find_element_by_id("your-image-id").get_attribute("src")
urllib.request.urlretrieve(url, "local-filename.jpg")
But this is really inefficient at scale, since I'd be submitting a ton of extra requests for images I already loaded (I tried benchmarking with this approach, and it was many times slower than Selenium's downloading and rendering, which was surprising)
I couldn't find a way of saving the images directly from Selenium, even though this seems like a pretty obvious feature they'd have. Is there a way of doing this? (I can switch away from Python if I absolutely need to.)