我想登录我的网上银行账户并打印交易记录。
我正在使用 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/