2

2 つのフォームに入力して、銀行の Web サイトにログインしようとしています。

ユーザー名を入力するための最初のフォームを取得できますが、パスワードを入力するためのフォームを取得できないようです。

私が使用しているコードは次のとおりです。

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)

パスワードフォームを入力するにはどうすればよいですか?

4

3 に答える 3

9

作業コードは次のとおりです。

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
于 2013-06-25T13:17:19.457 に答える
0

コードを深く掘り下げずに、そのサイト (ID が変更された場所を追加する可能性があります) をざっと見てみると、find_by_id('#easnhbcc') 呼び出しに余分な '#' を追加した可能性があります。「#」は ID の典型的な CSS 言語ですが、find_by_id() スプリンター呼び出しはそれを想定していません。また

find_by_id('easnhbcc')

また

find_by_css('#easnhbcc')

おそらくあなたのためにトリックをしたでしょう。

于 2015-01-25T00:07:51.493 に答える