Scraping HTML using a hashed class name is likely much more brittle than using the site's own API.
You don't need puppeteer to obtain the data in that table — you don't even need to scrape it: it's populated from data that's fetched without authentication from the following address (which I found in the dev tools network panel):
https://stats.nba.com/stats/synergyplaytypes?LeagueID=00&PerMode=Totals&PlayType=Isolation&PlayerOrTeam=T&SeasonType=Regular%20Season&SeasonYear=2022-23&TypeGrouping=offensive
It appears that the server only requires the appropriate Referer
header in order to get a response with a JSON body, so you can simply request the data this way:
example.mjs
:
const response = await fetch(
"https://stats.nba.com/stats/synergyplaytypes?LeagueID=00&PerMode=Totals&PlayType=Isolation&PlayerOrTeam=T&SeasonType=Regular%20Season&SeasonYear=2022-23&TypeGrouping=offensive",
{ headers: new Headers([["Referer", "https://www.nba.com/"]]) },
);
const data = await response.json();
// The actual data:
const resultSet = data.resultSets[0];
const teamNameIndex = resultSet.headers.indexOf("TEAM_NAME");
const teamNames = resultSet.rowSet.map((array) => array[teamNameIndex]);
console.log("first five teams:", teamNames.slice(0, 5));
console.log("entire payload:", JSON.stringify(data, null, 2));
In the terminal:
% node --version
v18.16.0
% node example.mjs
first five teams: [
'Dallas Mavericks',
'Philadelphia 76ers',
'Brooklyn Nets',
'New York Knicks',
'Oklahoma City Thunder'
]
entire payload: {
"resource": "synergyplaytype",
"parameters": {
"LeagueID": "00",
"SeasonYear": "2022-23",
"SeasonType": "Regular Season",
"PerMode": "Totals",
"PlayerOrTeam": "T",
"PlayType": "Isolation",
"TypeGrouping": "offensive"
},
"resultSets": [
{
"name": "SynergyPlayType",
"headers": [
"SEASON_ID",
"TEAM_ID",
"TEAM_ABBREVIATION",
"TEAM_NAME",
"PLAY_TYPE",
"TYPE_GROUPING",
"PERCENTILE",
"GP",
"POSS_PCT",
"PPP",
"FG_PCT",
"FT_POSS_PCT",
"TOV_POSS_PCT",
"SF_POSS_PCT",
"PLUSONE_POSS_PCT",
"SCORE_POSS_PCT",
"EFG_PCT",
"POSS",
"PTS",
"FGM",
"FGA",
"FGMX"
],
"rowSet": [
[
"22022",
1610612742,
"DAL",
"Dallas Mavericks",
"Isolation",
"Offensive",
0.828,
82,
0.122,
1.018,
0.423,
0.169,
0.07,
0.15,
0.031,
0.466,
0.485,
1064,
1083,
356,
842,
486
],
[
"22022",
1610612755,
"PHI",
"Philadelphia 76ers",
"Isolation",
"Offensive",
---snip---
],
---snip---
]
}
]
}