首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Splinter填写密码表单

使用Splinter填写密码表单
EN

Stack Overflow用户
提问于 2013-06-25 04:29:04
回答 3查看 11.1K关注 0票数 2

我正在尝试填写两张表格并登录我的银行网站。

我可以获得用户名要填写的第一个表单,但我似乎无法获得要填写密码的表单。

下面是我使用的代码:

代码语言:javascript
复制
from splinter import Browser

username2 = '***'
password2 = '***'

browser2 = Browser()
browser2.visit('http://mijn.ing.nl')

browser2.find_by_css('.firstfield').fill(username2)
browser2.find_by_id('#easnhbcc').fill(password2)

这是完整的回溯:

代码语言:javascript
复制
/usr/local/bin/python2 "/Users/narekaramjan/Dropbox/Python/Python 273/Test.py"
Traceback (most recent call last):
  File "/Users/narekaramjan/Dropbox/Python/Python 273/Test.py", line 26, in <module>
    browser2.find_by_id('#easnhbcc').fill(password2)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/element_list.py", line 73, in __getattr__
    self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'fill'

Process finished with exit code 1

我也尝试过:

代码语言:javascript
复制
browser2.find_by_name('easnhbcc').fill(password2)

我怎样才能填写密码表格?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-06-25 21:17:19

以下是工作代码:

代码语言:javascript
复制
from splinter import Browser     

# Define the username and password
username2 = '***'
password2 = '***'

# Choose the browser (default is Firefox)
browser2 = Browser()

# Fill in the url
browser2.visit('https://mijn.ing.nl/internetbankieren/SesamLoginServlet')

# Find the username form and fill it with the defined username
browser2.find_by_id('gebruikersnaam').first.find_by_tag('input').fill(username2)

# Find the password form and fill it with the defined password
browser2.find_by_id('wachtwoord').first.find_by_tag('input').fill(password2)

# Find the submit button and click
browser2.find_by_css('.submit').first.click()

# Print the current url
print browser2.url

# Print the current browser title
print browser2.title

# Print the current html source code
print browser2.html
票数 9
EN

Stack Overflow用户

发布于 2015-04-25 15:42:42

该错误指示您正在尝试填充元素列表。您只需选择列表中的一个元素。你可能想要这样的东西:

代码语言:javascript
复制
find_by_name('foo').first.fill()
票数 1
EN

Stack Overflow用户

发布于 2015-01-25 08:07:51

在不深入代码的情况下,快速浏览一下该站点(我可以补充一句,其中ID已更改),我会说您可能在find_by_id('#easnhbcc')调用中添加了额外的'#‘。'#‘是典型的表示ID的CSS语言,但find_by_id()拆分器调用并不需要它。任一

代码语言:javascript
复制
find_by_id('easnhbcc')

代码语言:javascript
复制
find_by_css('#easnhbcc')

可能已经帮你完成了这个戏法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17284522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档