打开一个网页,用机械化,我如何能继续提交
问题描述:
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>
我怎么能继续上?
答
因此,该解决方案非常简单,因为一旦您拥有浏览器实例,它就像真正的浏览器一样工作;在这个问题中,您可以在第一次成功提交后再次提交。
所以,这里是原代码:
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()