[英]Can't login using mechanize from python. What am I doing wrong?
I'm trying to use mechanize in python to login to this site: https://login.haaretz.co.il/ On the surface, it looks like a 2-phase login process, same as google, but following receipts for google login via mechanize gets me nowhere.我正在尝试使用 python 中的 mechanize 来登录这个站点: https://login.haaretz.co.il/表面上看起来像一个 2 阶段的登录过程,与 google 相同,但遵循 google 的收据通过机械化登录让我无处可去。 After submit()-ing the browser seems to remain on the same page, with a single form containing the single userName control.
在 submit() 之后,浏览器似乎保持在同一页面上,其中包含单个 userName 控件的单个表单。 What am I doing wrong?
我究竟做错了什么?
>>> import mechanize
>>> br = mechanize.Browser()
>>> br.open('https://login.haaretz.co.il/')
<response_seek_wrapper at 0x7f53bfbc4a00 whose wrapped object = <closeable_response at 0x7f53bfbc4580 whose fp = <_io.BufferedReader name=3>>>
>>>
>>> br.select_form(nr=0)
>>>
>>> print(br.form)
<GET https://login.haaretz.co.il/ application/x-www-form-urlencoded
<TextControl(userName=)>
<IgnoreControl(<None>=<None>)>>
>>> br['userName']='my_email@gmail.com'
>>> resp = br.submit()
>>> # and after submitting I'm back a square one
>>> print(br.forms()[0])
<GET https://login.haaretz.co.il/?userName=my_email%40gmail.com application/x-www-form-urlencoded
<TextControl(userName=)>
<IgnoreControl(<None>=<None>)>>
>>>
Is this hopeless?这是没有希望的吗? Am I doing it wrong?
我做错了吗?
My guess is that the login process depends on JavaScript.我的猜测是登录过程取决于 JavaScript。 If the login depends on JavaScript you won't get the results you want with Mechanize.
如果登录取决于 JavaScript,您将无法使用 Mechanize 获得所需的结果。 See Mechanize and Javascript
见机械化和 Javascript
The script tag at xpath 'body/script[2]'
has a JavaScript object with 'loginSuccess': False
key:value pair. xpath
'body/script[2]'
的脚本标签有一个 JavaScript object 和'loginSuccess': False
key:value 对。 Therefore my guess is that the login requires JavaScript.因此我的猜测是登录需要 JavaScript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.