【发布时间】:2021-10-24 07:51:19
【问题描述】:
我在 python 中编写了一些代码,允许我通过发送会话 cookie 来获取数据:
import requests
url = "https://fantasy.espn.com/apis/v3/games/ffl/seasons/2021/segments/0/leagues/1662510081?view=mRoster"
print(url)
r = requests.get(url,
cookies={'swid': '{A1cFeg47WrVdsREQZNAo}',
'espn_s2': 'AWDB51sqnG8dsc3wfdsffsd'})
d = r.json()
d
我想在 javascript 中实现这个,所以我写了:
let leagueId = 1662510081;
let endpoint = "mRoster";
let url =
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/2021/segments/0/leagues/" +
leagueId +
"?view=" +
endpoint;
console.log(url);
let playerList = [];
fetch(url)
.then((response) => response.json())
.then((data) => {
console.log(data)
});
如何在获取请求中实现 cookie?我在标头中尝试了 set-cookies,但没有成功。
【问题讨论】:
标签: javascript node.js fetch session-cookies