gpt4 book ai didi

Python请求超时

转载 作者:行者123 更新时间:2023-12-04 07:43:16 25 4
gpt4 key购买 nike

我一直试图从这里的链接中抓取表格:https://www.nba.com/stats/player/203999/passes-dash/ ,但是我在 XHR 选项卡下找到的包含我需要的表的端点完全超时/不返回我的请求。我没有多次发送请求,所以我不确定是不是这样,我尝试了不同数量的请求 header 、参数等。网站只是拒绝让我抓取吗?

import requests

url = 'https://stats.nba.com/stats/playerdashptpass?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=00&Location=&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PerMode=PerGame&Period=0&PlayerID=203999&Season=2020-21&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision='
header = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9'
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0',
'Origin': 'https://www.nba.com'
'Referer': 'https://www.nba.com/',
'Accept': 'application/json, text/plain, */*',
'Sec-Fetch-Site': 'same-site',
'x-nba-stats-origin': 'stats',
'x-nba-stats-token': 'true',
'Host':'stats.nba.com'
}

response = requests.get(url, headers=header)

最佳答案

你忘记了几个逗号...

import requests

url = 'https://stats.nba.com/stats/playerdashptpass?DateFrom=&DateTo=&GameSegment=&LastNGames=0&LeagueID=00&Location=&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PerMode=PerGame&Period=0&PlayerID=203999&Season=2020-21&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision='
header = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0',
'Origin': 'https://www.nba.com',
'Referer': 'https://www.nba.com/',
'Accept': 'application/json, text/plain, */*',
'Sec-Fetch-Site': 'same-site',
'x-nba-stats-origin': 'stats',
'x-nba-stats-token': 'true',
'Host':'stats.nba.com',
}

response = requests.get(url, headers=header)
print(response.text)
这应该工作...

关于Python请求超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67334453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com