[英]Filling a password form with Splinter
我正在嘗試填寫兩個表格並登錄到我的銀行網站。
我可以填寫用戶名的第一個表格,但似乎無法填寫密碼的形式。
這是我正在使用的代碼:
from splinter import Browser
username2 = '***'
password2 = '***'
browser2 = Browser()
browser2.visit('http://mijn.ing.nl')
browser2.find_by_css('.firstfield').fill(username2)
browser2.find_by_id('#easnhbcc').fill(password2)
這是完整的回溯:
/usr/local/bin/python2 "/Users/narekaramjan/Dropbox/Python/Python 273/Test.py"
Traceback (most recent call last):
File "/Users/narekaramjan/Dropbox/Python/Python 273/Test.py", line 26, in <module>
browser2.find_by_id('#easnhbcc').fill(password2)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/element_list.py", line 73, in __getattr__
self.__class__.__name__, name))
AttributeError: 'ElementList' object has no attribute 'fill'
Process finished with exit code 1
我也嘗試過:
browser2.find_by_name('easnhbcc').fill(password2)
如何獲取要填寫的密碼表單?
這是工作代碼:
from splinter import Browser
# 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
該錯誤表明您正在嘗試填充元素列表。 您只需要選擇列表中的元素之一。 您可能想要類似的東西:
find_by_name('foo').first.fill()
無需深入了解您的代碼,並快速瀏覽該站點(ID可能已更改的地方,我可能會添加),我想您可能會在find_by_id('#easnhbcc')調用中添加一個額外的“#”。 “#”是ID的典型CSS語言,但是find_by_id()分裂調用並不期望它。 要么
find_by_id('easnhbcc')
要么
find_by_css('#easnhbcc')
可能會為您完成竅門。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.