如何使用需要身份验证令牌的Python请求来模拟登录

时间:2016-03-22 08:59:43

标签: python http session web-scraping python-requests

我尝试使用请求登录此站点,但似乎他们使用了更复杂的身份验证登录。我没有太多的HTTP知识来了解需要做什么。感谢一些建议。我已截取以下相关信息。 我记录了一个实际登录。
Login Post Data
Authentication Page
我不了解身份验证页面中的信息。

下面的“我的代码”尝试按照实际网站所采取的步骤进行操作。

import requests
theedge1 = 'https://auth.theedgemarkets.com/login.html?_pt_=MQ%3D%3D'
theedge_login = 'https://auth.theedgemarkets.com/api/login'
theedge2 = 'https://auth.theedgemarkets.com/dialog/authorize?response_type=token&client_id=theedgemarkets4209&redirect_uri=http://www.theedgemarkets.com/user-login?url=http://www.theedgemarkets.com/my&scope=offline_access'
theedge3 = 'http://www.theedgemarkets.com/user-login?url=http://www.theedgemarkets.com/my'
root_edge = 'http://www.theedgemarkets.com/my'
payload_edge = dict(username='username', password='password')
with requests.Session() as s:
    s.get(theedge1)
    s.post(theedge_login, data=payload_edge)
    s.get(theedge2, headers=dict(referer=theedge1))
    s.get(theedge3)
    response = s.get(root_edge)

谢谢,非常感谢。

0 个答案:

没有答案