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

2024-09-19 23:27:44 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我使用了一个替代mechanize的方法,称为Splinter,因为它更易于使用,而且文档更清晰。在

我写的代码在填写密码表单时出错。我似乎无法成功识别密码表单域。因为它没有“name=”属性或css class属性。在

代码如下:

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()

完整的回溯:

^{pr2}$

Tags: 代码by属性findfillcssprinting
2条回答

根据斯普林特的文件,you can chain the finding methods。我建议你试试这个(我自己无法测试!)公司名称:

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,然后在其中查找输入字段时,它看起来更清晰/更干净。在

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

工作代码如下:

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

相关问题 更多 >