gpt4 book ai didi

python - split 对象没有属性点击

转载 作者:太空宇宙 更新时间:2023-11-04 06:01:54 25 4
gpt4 key购买 nike

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

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()

这是我得到的完整回溯

File "crosswalksplinter.py", line 9, in <module>
br.find_by_xpath('//*[id@"ct100_ct100_CIPContent_ContentPlaceHolder1_LinkButton_FINALCIPtoSOCcrosswalk"]').click()
File "/usr/lib/python2.6/site-packages/splinter/element_list.py", line 75, in __getattr__
self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'click'

我以前“点击”过类似的其他链接,所以我不确定这次是什么问题。有谁知道我为什么会收到此错误以及是否有解决方法?

最佳答案

根据错误消息,看起来从 br.find_by_xpath 返回的内容是一个列表,而不是单个元素。 splinter docs确认这一点:

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()

或者使用列表索引:

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

关于python - split 对象没有属性点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24437144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com