0

I'm very new a web scraping and have hit a issue with being able to check to see if I have reached a specific element in a list. The list changes length regularly, so I have been trying to check for the text/label of the element in the list, but the code I have tried has not worked.

Once the element "M" has been reached I want to exit the loop.

enter image description here

I have tried using the X-path, but the element number changes, last week it was: /html/body/ul/li[292]/div

this week it is [293], but the number will be changing often.

I have tried different approaches, my last one was using the class name "group"

element.driver.find_elements_by_class_name("group")

Any help or direction to any resources that may help are greatly appreciated!

Rodrigo Rodrigues
  • 7,545
  • 1
  • 24
  • 36
JoeMamma
  • 1
  • 1
  • Well, how do YOU know where the element is today? Whatever criteria that you, human (presumably) is using to track it, you can make the scraper to do. – Rodrigo Rodrigues Oct 10 '22 at 20:28
  • Can you confirm the url, is it publicly accessible? – Barry the Platipus Oct 10 '22 at 21:05
  • It's a website used for my job, stores currently open are on the list, but if they're temporarily closed they drop off the list. I can iterate through them using the xpath, but I'm just not sure how to approach the synatx to check the class name of the link to see if I'm in the "group" class – JoeMamma Oct 10 '22 at 21:30
  • You would need to provide some of your actual code, and what is the error you are currently getting – Rodrigo Rodrigues Oct 10 '22 at 21:36

1 Answers1

0

You can use xpath to loop through the list of li elements.

xpath = //li[@role='menuitem'][@class='ui-menu-item']/div

Then check for class attribute and validate if it contains entity-selected.

You can look for how to do this at link.

When found the element, use the [getText] to fetch the text contained in it. Look at this.

indayush
  • 55
  • 2
  • 9