python-2.7 - 使用 Python 的 Mechanize 模块验证 br.submit()

标签 python-2.7 mechanize mechanize-python

只是尝试使用 mechanize 登录网站。当我打印“br.form”时,我可以看到我的凭据输入到我的表单中。但我不知道如何正确提交表单。

我使用“br.submit()”并尝试通过打印 br.title() 来验证它是否已进入下一页,但出现的标题是针对登录屏幕的,而不是针对登录后屏幕的。

import mechanize
from time import sleep
def reportDownload():

    # Prompt for login credentials
    print("We require your credentials.")
    Username = raw_input("Please enter your username. ")
    Password = raw_input("Please input your password. ").encode('base64')

    URL = "https://login.xxxxxxxxx.com/"    
    br = mechanize.Browser()
    br.open(URL)    
    br.select_form(nr=0)

    br['username'] = Username
    br['pw'] = Password.decode('base64')

    print br.form       
    # Login 
    br.submit() 

    # print page title to confirm proper login
    print br.title()

reportDownload()

最佳答案

这可能会让您更好地了解正在发生的事情。

response = br.submit()
print response.read()

在 mechanize 中启用调试通常可能会有所帮助:

br.set_debug_http(True)
br.set_debug_responses(True)

关于python-2.7 - 使用 Python 的 Mechanize 模块验证 br.submit(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11531958/

相关文章:

python-2.7 - 使用Dockerfile和centos找不到make :7 image

python - 读取串行输入并打印到 Tkinter GUI

Python "private"函数编码约定

python - 使用 Mechanize (Python) 获取重定向日志

python - 可以打印但不能返回 html 表 : "TypeError: ResultSet object is not an iterator"

json - 如何从获取响应正文捕获值 - 机器人框架

python - 已安装 Mechanize,但 Python 找不到模块

python - Mechanize ,python : Read a specific line from a site to reduce read.() 长页时间

ruby-on-rails - Xpath 2.0 - xmlXPathCompOpEval : function matches not found

python - 斜纹/机械化访问 html 内容