我正在尝试使用 mechanize for python 登录网站;但是,当以表格形式提供正确的凭据时,它无法登录。
这是我按照机械化教程所做的事情:
def logon(self):
baseurl = "https://www.website.com/login"
br = mechanize.Browser(factory=mechanize.RobustFactory())
br.open(baseurl)
br.select_form(nr=0)
br.form["username"] = self.username
br.form["password"] = self.password
response = br.submit()
print response.geturl()
那应该把我带到 website.com/dashboard 但它在 website.com/login 页面上说好像它失败了。我可以手动登录,一切都通过调试器,所以我不确定我做错了什么。我做了一些挖掘,并检查了表单 HTML 中的 javascript,并且表单似乎没有任何附加内容。
这是表格:
<form method="post" class="login-form">
<fieldset>
<div class="row form-section">
<label for="email">Email Address</label>
<span class="input-text"><input class="required-email" type="text" id="email" value="" name="username" /><span class="required">Required Info</span></span>
<!--<input type="text" id="email" name="username" placeholder="Enter Email Address" class="text" aria-required="true" required="required" style='float:right;' size="30" value="" /><p> -->
</div>
<div class="row form-section">
<label for="pass">Password</label>
<span class="input-text"><input class="required-text" type="password" id="pass" value="" name="password" /><span class="required">Required Info</span></span>
<!--<input type="password" placeholder="Enter Password" class="text" size="30" autocomplete="off" value="" id="password" name="password" style='float:right;' aria-required="true" required="required" />-->
</div>
<div class="row row-btn">
<input type="submit" value="Log in" />
<span><a href="/sign-up" class="sign-in">Don't have an account?</a><br><br><a href="/component/com_oms/task,reset-password/view,user/" class="sign-in">Forgot your password?</a> <a href="/resend-activation" class="sign-in">Didn't get your activation email?</a></span>
</div>
</fieldset>
<input type="hidden" value="com_oms" name="option">
<input type="hidden" value="login" name="task">
<input type="hidden" name="return" value="">
<input type="hidden" name="9402951e32acb8d73d4a6972ae540c63" value="1" />
</form>
我知道有人问了一些类似的问题,但我的搜索似乎没有任何明确的答案。任何人都可以阐明发生了什么吗?