I want to get data from a website which is in table. First i try to get the whole table and then get the tr
‘s and td
‘s that are inside it. The code i have now just return empty array.
const puppeteer = require("puppeteer");
async function run() {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(
"https://www.basketball-reference.com/leagues/NBA_2021_standings.html" //Eastern Conference
);
var temp = [];
const data = await page.evaluate(() => {
const tableBody = document.querySelector(
'table[id="confs_standings_E"] tbody'
);
for (var i = 0; i < tableBody.length; i++) {
const tr = tableBody[i].querySelectorAll("tr");
for (var j = 0; j < tr.length; j++) {
const td = tr[j].querySelectorAll("td").innerText;
temp.push(td);
}
}
});
console.log(temp);
//await browser.close();
}
run();
Thanks for any help