Python 尝试使用mechanize登录到quora

Python 尝试使用mechanize登录到quora,python,http,mechanize,quora,Python,Http,Mechanize,Quora,我正在尝试使用mechanize模块登录quora.com 这是我的代码: #!/usr/bin/env python import mechanize import cookielib br = mechanize.Browser() # create a browser object br.set_handle_equiv(True) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots

我正在尝试使用
mechanize
模块登录quora.com

这是我的代码:

#!/usr/bin/env python

import mechanize
import cookielib

br = mechanize.Browser() # create a browser object
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_headers = [('User-Agent', 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)')]

cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

res = br.open('http://www.quora.com')
br.select_form(nr = 0)

br.form['email'] = 'uuuu'
br.form['password'] = 'pppp'

res = br.submit()
print res.read()
我得到这个错误:

Traceback (most recent call last):
  File "mech.py", line 29, in <module>
    res = br.submit()
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 541, in submit
    return self.open(self.click(*args, **kwds))
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 203, in open
    return self._mech_open(url, data, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 255, in _mech_open
    raise response
mechanize._response.httperror_seek_wrapper: HTTP Error 500: Internal Server Error
回溯(最近一次呼叫最后一次):
文件“mech.py”,第29行,在
res=br.submit()
文件“/usr/local/lib/python2.7/dist-packages/mechanize/_-mechanize.py”,第541行,提交
返回self.open(self.click(*args,**kwds))
文件“/usr/local/lib/python2.7/dist packages/mechanize/_mechanize.py”,第203行,打开
返回self.\u mech\u open(url、数据、超时=超时)
文件“/usr/local/lib/python2.7/dist-packages/mechanize/\u-mechanize.py”,第255行,处于打开状态
提出回应
mechanize.\u response.httperror\u seek\u包装器:HTTP错误500:内部服务器错误

我知道HTTP 500意味着服务器端出现了问题,但我不知道是什么问题,也不知道如何调试该问题。

我打赌
mechanize
无法处理提交此特定表单的问题。使用浏览器开发工具,您可以看到此表单是通过javascript XHR POST请求提交到
https://www.quora.com/webnode2/server_call_POST?__instart__
其中请求参数如下所示:

json:{"args":[],"kwargs":{"email":"<email>","password":"<password>","passwordless":1}}
formkey:62c4f0d88246bfd81b27cf0dca410d75
window_id:dep4-4597603286175583039
_lm_transaction_id:0.4317954108119011
_lm_window_id:dep4-4597603286175583039
__vcon_json:["hmac","t1cKg1QhQsYPCA"]
__vcon_method:do_login
js_init:{}
正如您所看到的:错误的URL和不同的参数

我会用这个特殊的例子


希望这能有所帮助。

您是如何发现这一切的?以及selenium的问题:正如我所说的,浏览器开发工具和机械化调试模式。我认为这个问题没有什么比这更能回答的了。无论如何,我会看看硒的问题。
email=<email>
allow_passwordless=allow_passwordless
password=<password>