seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.46k stars 910 forks source link

Extract URL of image and not base64 #2711

Closed lomanq closed 2 months ago

lomanq commented 2 months ago

Hi, i have this HTML:

<img class="active " src="https://m.media-amazon.com/images/I/61M5AtEKgrL._SS180_.jpg" width="180" height="180" title="">

I need the URL of the image: https://m.media-amazon.com/images/I/61M5AtEKgrL._SS180_.jpg

With this code:

from seleniumbase import Driver
driver_seleniumbase = Driver(uc=True)
image = driver_seleniumbase.find_element("img.active")
image_link = image.get_attribute("src")
print(image_link)

My output is a base64 image like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAA...

I need URL, i don't want to save image on my PC . How can i do this? Thanks

mdmintz commented 2 months ago

get_attribute("src") will get you the src of the element that you found ("img.active"), but you may need to use a better selector, because it looks like there's an earlier matching selector on that page, which is why you got a different src than the one you expected.