Two-Dimensional Array Method
You can also scrape the innerText
into a two-dimensional array representing your table.
[
['A1', 'B1', 'C1'], // Row 1
['A2', 'B2', 'C2'], // Row 2
['A3', 'B3', 'C3'] // Row 3
]
page.$$eval()
const result = await page.$$eval('#example-table tr', rows => {
return Array.from(rows, row => {
const columns = row.querySelectorAll('td');
return Array.from(columns, column => column.innerText);
});
});
console.log(result[1][2]); // "C2"
page.evaluate()
const result = await page.evaluate(() => {
const rows = document.querySelectorAll('#example-table tr');
return Array.from(rows, row => {
const columns = row.querySelectorAll('td');
return Array.from(columns, column => column.innerText);
});
});
console.log(result[1][2]); // "C2"