gpt4 book ai didi

python mechanize - 无法提交登录表单

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

我正在使用 mechanize ( http://wwwsearch.sourceforge.net/mechanize/ ) 登录 www.coinotron.com,但是当我执行 br.submit() 时执行挂起

import mechanize  
...
br = mechanize.Browser()
br.open("https://coinotron.com/app?action=logon")
form = br.select_form(nr=0)
br.form["name"] = "myusername"
br.form["password"] = "mypassword"
reponse = br.submit() # HERE THE EXECUTION HANGS!

如果我注释密码行,则脚本可以正常执行,但当然不会登录。

最佳答案

找到了一个解决方法,虽然我不完全理解它为什么起作用。但它认为 br.submit() 由于 HTTPRefreshProcessor.honor_time = True 和 HTTPRefreshProcessor.max_time 具有很大的值(value)而处于 sleep 状态。
所以我在 br = mechanize.Browser() 之后添加了以下行:

br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1, honor_time=True)

以下页面帮助了我,尽管与我的问题没有直接关系:
Mechanize in Python - Redirect is not working after submit

http://wwwsearch.sourceforge.net/mechanize/hints.html

关于python mechanize - 无法提交登录表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46746095/

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