繁体   English   中英

如何使用Python在Selenium中的元素中查找所有href

[英]How to find all href in an element in Selenium with Python

我已经找到一个元素,并希望在此元素中找到所有href。 我尝试获取所有链接,但仅获得第一个。

element = driver.find_element_by_xpath("//div[@class='msg']/div[@class='']")
href = element.find_element_by_css_selector('a').get_attribute('href') #only get first link 

正确的方法是什么?

非常感谢你。

请参阅Selenium文档

查找多个元素(这些方法将返回一个列表)...

CSS的多元素版本为find_elements_by_css_selector

element = driver.find_element_by_xpath("//div[@class='msg']/div[@class='']")
hrefs = [x.get_attribute('href') for x in element.find_elements_by_css_selector('a')]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM