Reputation: 121
I've been trying to scrape the tables from this link here: https://www.nba.com/stats/player/203999/passes-dash/, however the endpoint that I found under the XHR tab which has the tables I need is completely timing out/not returning my request. I haven't sent the request an obnoxious amount of times so I'm not sure it's that, and I've tried with a varying amount of Request headers, params, etc. Is the website simply refusing to let me scrape?
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)
Upvotes: 2
Views: 192
Reputation: 442
You forgot a few commas...
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)
This should work...
Upvotes: 2
Reputation: 25306
The website is down and is timing out in my web browser. You did it right, their website is down.
Upvotes: 0