Skip to content Skip to sidebar Skip to footer

Selenium: Get_attribute One Condition

I am scraping a website and do have a solution, but I am sure there is a better one. I do not like the if-statement and think there could be a better one. driver = webdriver.Chrom

Solution 1:

You can get required output with below one-liner:

verein = [img.get_attribute('alt') for img in driver.find_elements("css", ".tiny_wappen")]

Solution 2:

Faster and clean solution is to use Javascript:

verein = driver.execute_script("return [...document.querySelectorAll('img.tiny_wappen')].map(element => element.getAttribute('alt'));")

With pure selenium: img with tiny_wappen class

bilder=driver.find_elements_by_css_selector("img.tiny_wappen")
for b in bilder:
     verein.append(b.get_attribute('alt'))

Post a Comment for "Selenium: Get_attribute One Condition"