PYTHON Mechanize 登录表单类

标签 python mechanize

我尝试使用 Mechanize 登录到以下表单。

<div class="container">
    <form class="form-signin" id="form_login">
        <h2 class="form-signin-heading"><center>GReAT Sinkhole Database</center></h2>
        <div id="form_login_error_box" class="form_error_box"></div>
        <label for="form_username" class="sr-only">Username</label>
        <input type="text" id="form_username" class="form-control" placeholder="Username" required autofocus>
        <label for="form_password" class="sr-only">Password</label>
        <input type="password" id="form_password" class="form-control" placeholder="Password" required>

        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
    </form>
</div>

Mechanize 浏览器方法br.submit()br.click()没有提交我的表单,我也没有检索到想要的 HTML。

这是代码
browser.select_form(nr = 0)
browser.form.set_value(login_user, nr=0)
browser.form.set_value(Loginpwd, nr=1)
ff = browser.submit()
print " title ##" + str(browser.title())
print ff.read()

应该是什么?

最佳答案

<form>元素没有 methodaction属性。

没有方法的表单的默认行为是通过 GET 请求提交,由于没有定义 Action ,我猜他们会提交到页面的 url (HTML 规范没有指定如果没有定义 Action 会发生什么) .登录表单不太可能像这样。

因此,此表单似乎是通过 javascript 提交的,并且无法使用 Mechanize 进行访问。

关于PYTHON Mechanize 登录表单类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36372948/

相关文章:

python - 从新闻网站中提取用户评论

python函数在 Pyramid 中的行为不同?

ruby - 无法点击 td 元素

python - 如何使用 winsound 阻止声音相互叠加? (Python 和 tkinter)

python - 值错误: invalid literal for int() with base 10: 's'

python - 在 Python C API 中将新类定义为结构有什么意义

html - Mechanize 不像浏览器那样处理 cookie

python - 导入 mechanize 时在 python3 中出现错误

javascript - 如何抓取网站投资以获​​得股票的每项技术分析

python - 简单移动平均线 (SMA) 函数