gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:21:06 24 4
gpt4 key购买 nike

我正在尝试在 python 中使用 mechanize 登录此站点:https://login.haaretz.co.il/
从表面上看,它看起来像一个两阶段的登录过程,与谷歌相同,但通过 Mechanize 登录谷歌的收据让我无处可去。在 submit()-ing 之后,浏览器似乎保持在同一页面上,具有包含单个 userName 控件的单个表单。
我究竟做错了什么?

>>> 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>)>>
>>>
这是没有希望了吗?我做错了吗?

最佳答案

我的猜测是登录过程取决于 JavaScript。如果登录依赖于 JavaScript,您将无法通过 Mechanize 获得想要的结果。见 Mechanize and Javascript
xpath 中的脚本标签 'body/script[2]'有一个带有 'loginSuccess': False 的 JavaScript 对象键:值对。因此我的猜测是登录需要 JavaScript。

关于python - 无法使用 python 中的 Mechanize 登录。我究竟做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66079501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com