请帮助我找到解决方案,以获取“ul”标签内的文本
我想得到用逗号分隔的信息,如:“含有酶活性B族维生素、膳食补充剂、非转基因LE认证”
网站链接:https://ca.iherb.com/pr/Life-Extension-BioActive-Complete-B-Complex-60-Vegetarian-Capsules/67051
图片:enter image description here
这是HTML代码:
<ul>
<li>Contains Enzymatically Active B-Vitamins
</li>
<li>Dietary Supplement
</li>
<li>Non-GMO LE Certified
</li>
</ul>
要使用Selenium和python提取文本,例如,含有酶活性B族维生素,膳食补充剂,您可以使用以下任何一种Locator Strategies:
使用
CSS_SELECTOR
并打印列表:控制台输出:
使用
XPATH
并以逗号分隔的字符串打印元素:控制台输出:
要提取文本,例如含有酶活性B族维生素,膳食补充剂,理想情况下,您必须诱导WebDriverWait用于
visibility_of_all_elements_located()
,并且您可以使用以下任何一种Locator Strategies:使用
CSS_SELECTOR
并打印列表:控制台输出:
使用
XPATH
并以逗号分隔的字符串打印元素:控制台输出:
注意:您必须添加以下导入:
您始终可以获取所有元素
li
,从所有这些元素获取文本并使用", ".join(elements)
为您的小示例编写代码
这应该做到:
输出:
相关问题 更多 >
编程相关推荐