2017-09-13 44 views
0
import mechanize 
br = mechanize.Browser() 
br.open('someurl.com') 
br.select_form(nr=0) 
br.form['user'] = 'myname' 
br.form['pw'] ='pw' 
req=br.submit() 

後提交後,我登錄了新的一頁,這進一步要求我點擊「下一步」打開一個網頁,用機械化,我如何能繼續提交

<input type="submit" value=" Next " name="B1"> <input type="reset" value=" Clear " name="B2"></td> 

我怎麼能繼續上?

回答

0

因此,該解決方案非常簡單,因爲一旦您擁有瀏覽器實例,它就像真正的瀏覽器一樣工作;在這個問題中,您可以在第一次成功提交後再次提交。

所以,這裏是原代碼:

import mechanize 
br = mechanize.Browser() 
br.open('someurl.com') 
br.select_form(nr=0) 
br.form['user'] = 'myname' 
br.form['pw'] ='pw' 
req=br.submit() 

然後重複你做了什麼,以移動到下一個頁面(下面是完整的解決方案):

import mechanize 
br = mechanize.Browser() # now you are at first login page 
br.open('someurl.com') 
br.select_form(nr=0) # select the form from the first login page 
br.form['user'] = 'myname' 
br.form['pw'] ='pw' 
req=br.submit() # now you are at second login page 
br.select_form(nr=0) # select the form from the second login page 
br.form['user'] = 'myname' 
br.form['pw'] ='pw' 
req=br.submit()