jake wong
jake wong

Reputation: 5228

Python Selenium get image name from website

I am trying to scrape a website for my project, but i'm having trouble with scrapping image names via Selenium from this website

enter image description here

with the below code, I am able to use selenium to return me the text data from the website

results = driver.find_elements_by_css_selector("li.result_content")

for result in results:
    company_name = result.find_element_by_tag_name("h3").get_attribute("innerText")
    product_name = result.find_element_by_id('sProdName').get_attribute("innerText")
    product_paymode = result.find_element_by_id('paymode').get_attribute("innerText")

I was told to use get_attribute("innerText") because there are several items hidden, and get_attribute("innerText") would help me get the hidden items. (True enough, it works)

my question is: How do I scrape the prod-feature-icon class, to tell me if that picture is active or not??

Upvotes: 2

Views: 1817

Answers (1)

e4c5
e4c5

Reputation: 53734

Why not use find_element_by_class_name ?

feature_icon = result.find_element_by_class_name("prod-feature-icon")

However it's worth noting that the object with this class name is actually a UL within it there are several images so you need to decide which image exactly you want to work with from that. Alternatively you could iterate through them with

for item in feature_icon.find_elements_by_tag_name('img'):
    print(item.get_attribute('src'))

of course this wouldn't still tell you whether the item is active or inactive because that doesn't seem to be dictated by the CSS but rather by the shading of the image

Upvotes: 2

Related Questions