代码错误的原因是find_elements方法返回的是一个元素列表,而不是单个元素。因此,不能直接使用get_attribute方法来获取href属性。

正确的做法是遍历元素列表,针对每个元素使用get_attribute方法来获取href属性。可以使用循环或列表推导式来实现:

elements = driver.find_elements(By.TAG_NAME,'a')
href_list = [element.get_attribute('href') for element in elements]

这样就可以将所有<a>标签的href属性值保存在href_list列表中了。

代码find_elementsByTAG_NAMEaget_attributehref错误原因

原文地址: https://www.cveoy.top/t/topic/ikWc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录