python - 如何登录我的网上银行账户并打印交易记录?

标签 python login passwords mechanize urllib

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

我正在使用 mechanize 的替代方案叫 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

最佳答案

在 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

关于python - 如何登录我的网上银行账户并打印交易记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17293390/

相关文章:

python - 使用索引获取项目

ipad - Google API-如何将URL重定向到我的本地主机

android - 应用程式尝试登入网页时当机

postgresql - 尽管有开放的信任设置,Postgres 9.2 数据库仍要求输入密码

visual-studio-2010 - 如何在vc++中创建密码字段和按钮

python - 在Windows上的Python 2.7中将标签应用于WAV文件

python - 将多行字符串转换为数据框

security - 修改SVN密码命令行

python - 使用 imaplib 使用文件中的凭据登录 Gmail

php - 检查数据库上的用户名和密码(包括脚本)