Python:如何登录stockcharts并获取会话保护页面的内容?

2024-06-28 20:48:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我想登录stockcharts.com网页,然后在登录后使用其用户可用的内容。在

以下是我尝试的:

from requests import session

payload = { 'form_Name':         'Login',
            'zendesk_timestamp': '',
            'redirect':          '',
            'form_UserID':       'XXXX@YYY.com',
            'form_UserPassword': 'ZZZZ',
            'form_RememberMe':   ''
            }

c        = session()
this_url = 'https://stockcharts.com/scripts/php/dblogin.php'

c.post( this_url, data = payload )

request = c.get( 'http://stockcharts.com/h-hd/?GOOG' )

然后,我使用获取的历史数据。在

我使用了spyder,下面是我收到的错误消息:

^{pr2}$

我已经在谷歌上搜索了一段时间,尝试了一些类似的东西(代码和标题实际上是“借用”的)

How to use Python to login to a webpage and retrieve cookies for later usage?

Python login to webpage and get contents of session protected page

我就是不能让它为我工作。我使用Python有一段时间了,但我觉得我对这种编程还是不熟悉的。在

有人能帮我吗?非常感谢你的帮助!!在

JW公司


Tags: andto用户formcomurl网页get
1条回答
网友
1楼 · 发布于 2024-06-28 20:48:12

问题不在Python中,而是<form <input ...>语法

您可能需要深入到当前的登录界面。在

dblogin.php期望(截至2014年10月12日)收到这组参数:

  1. form_Name == "Login"
  2. zendesk_timestamp
  3. redirect
  4. form_UserID == <<_aText_>>
  5. form_UserPassword == <<_aText_>>
  6. form_RememberMe

因此,您需要满足php-接口的期望,以使这一步走得更远。在

提交后,您应检查您的真实(手动)登录值,空白/空字符串不起替代作用。在

相关问题 更多 >