带有Python的Morningstar请求获取10年财务数据

时间:2019-07-18 22:46:58

标签: python-3.x

看来How can I log in to morningstar.com without using a headless browser such as selenium?中的Morningstar登录解决方案对我而言不再有效。 我收到错误消息{'message':'Forbidden'},我认为这是由于解决方案“ https://www.morningstar.com/api/v2/user/login”中使用了login_url

有什么解决方法吗?

import requests

s = requests.session()
auth_url = 'https://sso.morningstar.com/sso/json/msusers/authenticate'
login_url = 'https://www.morningstar.com/api/v2/user/login'
username = 'username'
password = 'password'

headers = {
    'Access-Control-Request-Method': 'POST',
    'Access-Control-Request-Headers': 'content-type,x-openam-password,x-openam-username',
    'Origin': 'https://www.morningstar.com'
}
s.options(auth_url, headers=headers)

headers = {
    'Referer': 'https://www.morningstar.com/members/login.html',
    'Content-Type': 'application/json',
    'X-OpenAM-Username': username,
    'X-OpenAM-Password': password,
    'Origin': 'https://www.morningstar.com',
}
s.post(auth_url, headers=headers)

data = {"productCode":"DOT_COM","rememberMe":False}
r = s.post(login_url, json=data)

print(s.cookies)
print(r.json())

0 个答案:

没有答案