碎片对象没有属性cli

2024-05-23 13:42:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从教育部下载一个文件,这是我目前为止的完整代码:

from splinter import Browser
import time

br = Browser()
br.visit('http://nces.ed.gov/ipeds/cipcode/resources.aspx?y=55')
br.find_by_xpath('//*[id@"ct100_ct100_CIPContent_ContentPlaceHolder1_LinkButton_FINALCIPtoSOCcrosswalk"]').click()

# give myself a delay to visually inspect that it's working
time.sleep(5)
br.quit()

这是我得到的完整的回溯

^{pr2}$

我以前“点击”过其他类似的链接,所以我不确定这次有什么问题。有人知道我为什么会犯这个错误吗?有没有办法解决它?在


Tags: 文件代码frombrimportbrowserhttptime
1条回答
网友
1楼 · 发布于 2024-05-23 13:42:56

根据错误消息,br.find_by_xpath返回的内容似乎是一个列表,而不是一个元素。^{}确认:

Splinter provides 6 methods for finding elements in the page, one for each selector type: css, xpath, tag, name, id, value. ... Each of these methods returns a list with the found elements.

它还说:

You can get the first found element with the first shortcut:
first_found = browser.find_by_name('name').first

尝试单击第一个元素,如下所示:

br.find_by_xpath('//*[id@"ct100_ct100_CIPContent_ContentPlaceHolder1_LinkButton_FINALCIPtoSOCcrosswalk"]').first.click()

或者使用列表索引:

^{pr2}$

相关问题 更多 >