alperiox

extract dietary attributes

Oct 29th, 2022 (edited)
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. # A>B means the B elements where A is the parent element.
  2. dietary_attrs = element.find_elements(By.CSS_SELECTOR, "div[class*='DietaryAttributes']>span")
  3. # if there aren't any, then `dietary_attrs` will be None and `if` block won't work
  4. # but if there are any dietary attributes, extract the text from them
  5. if dietary_attrs:
  6.     dietary_attrs = [attr.text for attr in dietary_attrs]
  7. else:
  8.     # set the variable to None if there aren't any dietary attributes found.
  9.     dietary_attrs = None
Advertisement
Add Comment
Please, Sign In to add comment