1

enter image description here

I am trying to get the image link from this page.

 def save_score(self):
        element_lst = self.driver.find_elements_by_class_name('ingredient-score score-popup')
        score_lst = [element.get_attribute('src') for element in element_lst]
        return len(element_lst)

But it seems like selenium can't get the elements when I am finding it by the class name. In this table I have 8 image links that I want to scrape. Is there any way around to achieve this? Maybe using Xpath?

2 Answers 2

2

when you're using class as Selector we don't use space between the values, instead of "ingredient-score score-popup" try with "ingredient-score.score-popup". I leave this reference page

Sign up to request clarification or add additional context in comments.

Comments

0

Since that element has multiple class names you should use css_selector or xpath. Lie this:

def save_score(self):
        element_lst = self.driver.find_elements_by_css-selector('img.ingredient-score.score-popup')
        score_lst = [element.get_attribute('src') for element in element_lst]
        return len(element_lst)

or

def save_score(self):
        element_lst = self.driver.find_elements_by_xpath('//img[@lcass="ingredient-score score-popup"]')
        score_lst = [element.get_attribute('src') for element in element_lst]
        return len(element_lst)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.