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:
JavaScript
x
9
1
<ul>
2
<li>Contains Enzymatically Active B-Vitamins
3
</li>
4
<li>Dietary Supplement
5
</li>
6
<li>Non-GMO LE Certified
7
</li>
8
</ul>
9
Advertisement
Answer
This should do it:
JavaScript
1
9
1
from selenium import webdriver
2
3
link = 'https://ca.iherb.com/pr/Life-Extension-BioActive-Complete-B-Complex-60-Vegetarian-Capsules/67051'
4
5
with webdriver.Chrome() as driver:
6
driver.get(link)
7
elements = ', '.join([item.text for item in driver.find_elements_by_css_selector("[itemprop='description'] > ul:nth-of-type(1) > li")])
8
print(elements)
9
Output:
JavaScript
1
2
1
Contains Enzymatically Active B-Vitamins, Dietary Supplement, Non-GMO LE Certified
2