我正在尝试设置一个应用程序,以便我可以从 ESPN Fantasy 网站上的联盟中抓取 Fantasy Football 数据。为了实现这个功能,我正在尝试学习如何使用 Python 上的 Requests 模块登录网站,但我遇到了一个问题。在浏览 ESPN 登录页面上的 HTTP 网络内容时,我设法找到了“POST”请求 URL,但该页面似乎是故意设置为阻止这种确切类型的尝试(或者也许我太缺乏经验,无法计算出来)。
下图中显示的 URL 会将您带到一个空白网页,其中包含以下文本:
{"data":null,"error":{"keyCategory":"FAILURE_BY_DESIGN","conversationId":null,"correlationId":"d2f53819-03f1-4247-832d-210bbe112053","errors":[{"code ":"AUTHORIZATION_INVALID_OR_EXPIRED_TOKEN","category":"FAILURE_BY_DESIGN","inputName":null,"errorId":"47126869-c7d0-4f79-b7cd-7797cda2f57a","timestamp":"2021-09-20T14:58:34.845 -0700","数据":null,"developerMessage":null,"content":null}]}}
有谁知道是否有更好的方法来尝试使用 Python 和请求登录到这样的页面?
import requests
import json
def login(mail, password):
s = requests.session()
payload = {
'email': mail,
'password': password
}
res = s.post('https://registerdisney.go.com/jgc/v6/client/ESPN-ONESITE.WEB-PROD/guest/login?langPref=en-US', json=payload)
s.headers.update({'authorization': json.loads(res.content)})
print (res.content)
return s
session = login('myemail', 'my password')
