Python请求超时

标签 python python-requests

我一直在尝试从此链接中抓取表格: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/

相关文章:

python - 迭代 n 个值

python - 在非根 conftest.py 中使用 pytest_addoptions

Python Pip 安装 SSL 错误 749

python - 为什么使用带有 post 的表单在 python 中发送图像不起作用

python - 列表列表中子列表的最大和

python - 如何在 python 请求中获取 cookie 信息?

python - 在 python 函数中使用全局变量

python - 将重试封装到 `with` block 中

php - 如何获取链接您的图像的网站的 URL?

python - QPython无法安装requests模块