嗯,我正嘗試使用Python和機械化登錄到一個站點。使用機械化提交表單(Python)
我已經得到了網站開通:
site = br.open("http://example.com/login.php")
而且我已經得到的表單列表(與br.forms)。
<GET http://example.com/search.php application/x-www-form-urlencoded
<HiddenControl(search=1) (readonly)>
...
<POST http://example.com/login.php application/x-www-form-urlencoded
<TextControl(username=)>
<PasswordControl(password=)>
<CheckboxControl(stay=[1])>
<SubmitControl(<None>=Log in) (readonly)>>
我一直在試圖提交用戶名和密碼字段。
我試圖做這樣的:
br.select_form(nr=0)
br.form["username"] = 'usernamehere'
br.form["password"] = 'passwordhere'
br.submit()
然後我意識到,我試圖填寫表格不是第一個在頁面上,但改變0不與任何幫助。我應該如何選擇這樣的頁面上的表單?
但是!這不是唯一的問題。
當我運行它,我得到這個錯誤:
Traceback (most recent call last):
File "C:\Python26\login.py", line 34, in <module>
br.form["username"] = 'usernamehere'
...
ControlNotFoundError: no control matching name 'username'
我該如何解決這個問題? D:還是我做錯了?如果是後者,我該如何去做呢?
br.select_form(name =「username」)拋出一個錯誤:FormNotFoundError:沒有匹配名稱'username'的表單 - 與以前一樣,但是這次是我剛剛添加的行。 – Matthew 2011-12-20 05:25:54
你確定你有正確的名字嗎?試試br.forms()中的表單:print form – tovmeod 2011-12-22 01:27:40
Positive。我檢查了br.forms()和原始html。 – Matthew 2011-12-27 08:12:03