0

我想登录我的网上银行账户并打印交易记录。

我正在使用一种名为Splinter的机械化替代品,因为它更易于使用且文档更清晰。

我写的代码在尝试填写密码表单时给了我一个错误。我似乎无法成功识别密码表单字段。因为它没有 "name=" 属性或 css 类属性。

这是代码:

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

browser2 = Browser()
browser2.visit('https://mijn.ing.nl/internetbankieren/SesamLoginServlet')
browser2.find_by_css('.firstfield').fill(username2)
browser2.find_by_id('#ewyeszipl').fill(password2)
browser2.click_link_by_text('Inloggen')

url2 = browser2.url
title2 = browser2.title

titlecheck2 = 'Mijn ING Overzicht  - Mijn ING'

print "Stap 2 (Mijn ING):"

if title2 == titlecheck2:
    print('Succeeded')

    print 'The source is:'
    print browser2.html

    browser2.quit()

else:
    print('Failed')

    browser2.quit()

完整的追溯:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python "/Users/*/Dropbox/Python/Test environment 2.7.3/Splinter.py"
Traceback (most recent call last):
  File "/Users/*/Dropbox/Python/Test environment 2.7.3/Splinter.py", line 45, in <module>
    browser2.find_by_id('#ewyeszipl').fill_form(password2)
  File "/Users/*/Library/Python/2.7/lib/python/site-packages/splinter/element_list.py", line 73, in __getattr__
    self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'fill_form'

Process finished with exit code 1
4

2 回答 2

2

在 Miklos 的帮助下解决了问题。

这是工作代码:

from splinter import *     

# 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
于 2013-06-25T12:56:06.573 回答
1

根据 Splinter 的文档,您可以链接查找方法。我建议你试试这个(我自己无法测试!):

browser2.find_by_id('gebruikersnaam').first.find_by_tag('input').fill(username2)
browser2.find_by_id('wachtwoord').first.find_by_tag('input').fill(password2)

请注意,我还更改了查找用户名输入字段的说明,即使您可以使用.firstfieldCSS 类找到它。我只是认为当您首先选择包含 div 然后在其中查找输入字段时,它看起来更清晰/更清晰。

于 2013-06-25T11:47:58.457 回答