gpt4 book ai didi

python - 在 python mechanize 中检查错误或成功

转载 作者:行者123 更新时间:2023-11-28 18:45:15 26 4
gpt4 key购买 nike

如何检查提交是否成功。当我提供正确的用户名时,它不显示任何内容。但即使我提交了错误的用户名,它也不会抛出任何错误。如何捕获错误或检查成功结果。任何帮助将不胜感激。谢谢。

代码:

try:
import mechanize
except ImportError:
print "Could not import Mechanize. Please install from Mechanize website."
br = mechanize.Browser()
interletter = 'http://somesite.com/adminpanel/index.php'
br.open(interletter)
print br.geturl()

br.select_form(name="frm_login")
br["admin_userid"] = "user"
br["admin_password"] = "pword"
result2 = br.submit()


http://somesite.com/adminpanel/index.php
<response_seek_wrapper at 0x25a3cb0 whose wrapped object = <closeable_response at 0x25ab738 whose fp = <socket._fileobject object at 0x025A0970>>>

最佳答案

您正在处理的 Web 服务器可能仍在发送 HTTP 200 状态代码,即使您的登录失败也是如此。他们可能只是在响应正文中包含错误文本。

您应该能够调用 result2.read() 来获取响应对象的内容。然后,您必须检查或解析它以确定您的登录尝试是否成功。

关于python - 在 python mechanize 中检查错误或成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21432314/

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