我有这样一部分代码,并希望收到我在“统计信息链接”中找到的元素的链接。 但它给了我一个错误,并写道:
AttributeError: 'list' object has no attribute 'get_attribute'
下面是包含JS元素http://www.ukrstat.gov.ua/head.html的html页面的结构 因此,我需要找到写有“统计信息”的链接——“Сааааааааааааааааа
r = requests.get("http://www.ukrstat.gov.ua/")
soup = BeautifulSoup(r.text)
head=soup.find('frame',{'name': 'banner'})
#Recieve link on head
link_head='http://www.ukrstat.gov.ua/'+head.get('src')
browser.get(link_head)
statistic_info_link = browser.find_elements_by_xpath("//*[contains(text(), 'Статистична інформація')]").get_attribute("outerHTML")
print(statistic_info_link)
谢谢你的帮助
该错误说明您试图在Python中调用列表上的
get_attribute
,但它应该是一个web元素记住
find_elements
(复数)在Python Selenium绑定中返回一个列表。其中asfind_element
在Python Selenium绑定中返回一个web元素问题解决方案:
因此,与其
这样做:
另外,我对
outerHTML
也不是很确定,因此我把它改成了innerHTML
第二次修复:
使用列表索引:
或
最后,如果您确实想从列表中提取文本,请使用以下代码:
或
由于您正在给
browser.find_elements
,它将返回列表中的元素。您可以对一个WebElement使用.get_attribute
,而不是列出WebElement将
statistic_info_link = browser.find_elements
更改为或者遍历列表
相关问题 更多 >
编程相关推荐