简体   繁体   English

无法使用 python 中的 mechanize 登录。 我究竟做错了什么?

[英]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.

相关问题 尝试使用Python验证SHA1消息签名。我究竟做错了什么? - Trying to verify SHA1 message signature using Python. What am I doing wrong? 我无法使用 Python 将名称中包含空格的文件上传到 Google Cloud Storage。 我究竟做错了什么? - I'm unable to upload a file whose name has a space in it to Google Cloud Storage using Python. What am I doing wrong? 将带字母的电话号码转换为python中的所有数字。 我究竟做错了什么? - translating phone number with letter to all numbers in python. what am i doing wrong? Lexer在Python中输出“ TypeError:write()参数必须为str,而不是字节”。 我究竟做错了什么? - Lexer Outputs “TypeError: write() argument must be str, not bytes” in Python. What am I doing wrong? 如果==不适用于python中的列表。 不知道我在做什么错。 数据的print()表明它们是相等的……我缺少什么? - IF == not working for lists in python. No idea what I am doing wrong. A print() of the data reveals they are equal…what am I missing? 我无法从Django中的模板访问相关字段,但是它在Shell中有效,我在做什么错? - I can't access a related field from a template in Django, but it works in the shell, what am I doing wrong? 在 Python 中使用季节性分解时我做错了什么? - What am I doing wrong when using seasonal decompose in Python? 我在使用函数的Python程序中怎么了? - What am I doing wrong in this Python program using functions? 从 python 程序导出数据我做错了什么? - What am I doing wrong with exporting data from a python program? 我在GitHub的Python示例代码中怎么了? - What am I doing wrong in this Python example code from GitHub?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM