Please help me to find the solution to get the text inside ‘ul’ tag.
I want to get the information which is separated with commas like: ‘Contains Enzymatically Active B-Vitamins, Dietary Supplement, Non-GMO LE Certified’
website link: https://ca.iherb.com/pr/Life-Extension-BioActive-Complete-B-Complex-60-Vegetarian-Capsules/67051
picture: enter image description here
This is the HTML code:
<ul> <li>Contains Enzymatically Active B-Vitamins </li> <li>Dietary Supplement </li> <li>Non-GMO LE Certified </li> </ul>
Advertisement
Answer
This should do it:
from selenium import webdriver link = 'https://ca.iherb.com/pr/Life-Extension-BioActive-Complete-B-Complex-60-Vegetarian-Capsules/67051' with webdriver.Chrome() as driver: driver.get(link) elements = ', '.join([item.text for item in driver.find_elements_by_css_selector("[itemprop='description'] > ul:nth-of-type(1) > li")]) print(elements)
Output:
Contains Enzymatically Active B-Vitamins, Dietary Supplement, Non-GMO LE Certified