gpt4 book ai didi

python - 用 Mechanize 打开网页后,如何继续提交

转载 作者:行者123 更新时间:2023-12-04 16:21:14 26 4
gpt4 key购买 nike

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()

关于python - 用 Mechanize 打开网页后,如何继续提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46191883/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com