![](/img/trans.png)
[英]How to get the image in get_attribute("style") in webdriver selenium in a page?
[英]Python Selenium Webdriver: how to select more than one element using get_attribute
我正在尝试使用以下命令在给定页面上找到网址:
driver.find_element_by_css_selector('.listing-title a').get_attribute('href')
这足以抓取第一个网址。 但是,我不知道如何在页面上获取其他href属性。 我尝试将s
添加到element
:
driver.find_elements_by_css_selector('.listing-title a').get_attribute('href')
但是我收到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'get_attribute'
有什么建议吗?
我想通了, find_elements_by_css_selector
返回一个列表,所以我需要遍历它:
x = driver.find_elements_by_css_selector('.listing-title a')
for each in x:
print each.get_attribute('href')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.