Python 如何登录我的网上银行帐户并打印交易历史记录?

Python 如何登录我的网上银行帐户并打印交易历史记录?,python,login,passwords,mechanize,urllib,Python,Login,Passwords,Mechanize,Urllib,我想登录我的网上银行帐户并打印交易历史记录 我使用另一种方法来调用它,因为它更易于使用,而且文档更清晰 我编写的代码在尝试填写密码表单时出错。我似乎无法成功识别密码表单字段。因为它没有“name=”属性或css类属性 代码如下: username2 = '***' password2 = '***' browser2 = Browser() browser2.visit('https://mijn.ing.nl/internetbankieren/SesamLoginServlet') bro

我想登录我的网上银行帐户并打印交易历史记录

我使用另一种方法来调用它,因为它更易于使用,而且文档更清晰

我编写的代码在尝试填写密码表单时出错。我似乎无法成功识别密码表单字段。因为它没有“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
/Library/Frameworks/Python.framework/Versions/2.7/bin/Python”/Users/*/Dropbox/Python/Test environment 2.7.3/Splinter.py“
回溯(最近一次呼叫最后一次):
文件“/Users/*/Dropbox/Python/Test-environment 2.7.3/Splinter.py”,第45行,在
浏览器2.按id(“#ewyeszipl”)查找。填写表格(密码2)
文件“/Users/*/Library/Python/2.7/lib/Python/site packages/splinter/element_list.py”,第73行,在__
self.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
AttributeError:'ElementList'对象没有属性'fill\u form'
进程已完成,退出代码为1

根据Splinter的文档。我建议你试试这个(我自己无法测试!)


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

根据Splinter的文档。我建议你试试这个(我自己无法测试!)


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

问题在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

问题在米克洛斯的帮助下解决了

以下是工作代码:

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

我认为这不是一个明智的想法,银行有很多安全措施,而自动脚本可能会引起警报,这可能导致对你的调查,这可能导致刑事指控。银行可能有某种类型的API,但在尝试执行此操作之前,您应该检查银行的政策。阅读错误消息,您似乎只需要将这一行上的fill_form()替换为fill():
browser2。按id(“#ewyeszipl”)查找。fill_form(password2)
。这行吗?@Inbar Rose这在这里是完全合法的。这不会是一个问题。银行没有API。@Miklos Aubert,我有,但不幸的是它仍然不起作用。这可能是一个与cookie相关的问题吗?我认为这不是一个明智的想法,银行有很多安全措施,而且自动脚本可能会引起警报,这可能导致对您的调查,从而导致刑事指控。银行可能有某种类型的API,但在尝试执行此操作之前,您应该检查银行的政策。阅读错误消息,您似乎只需要将这一行上的fill_form()替换为fill():
browser2。按id(“#ewyeszipl”)查找。fill_form(password2)
。这行吗?@Inbar Rose这在这里是完全合法的。这不会是一个问题。银行没有API。@Miklos Aubert,我有,但不幸的是它仍然不能工作。这可能是与cookie相关的问题吗?非常感谢Miklos。我删除了“gebruikersnaam”和“wachtwoord”之前的标签,以使代码正常工作。非常感谢Miklos。我删除了“gebruikersnaam”和“wachtwoord”之前的hashtag,以使代码正常工作。