我想登录我的网上银行帐户并打印交易历史记录。在
我使用了一个替代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}$
根据斯普林特的文件,you can chain the finding methods。我建议你试试这个(我自己无法测试!)公司名称:
请注意,我还更改了指令以查找用户名的输入字段,即使您可以使用
.firstfield
CSS类找到它。我只是觉得当您首先选择包含div,然后在其中查找输入字段时,它看起来更清晰/更干净。在在米克洛斯的帮助下问题解决了。在
工作代码如下:
相关问题 更多 >
编程相关推荐