You can scrape HTML tables in JavaScript by first selecting the table elements and then accessing its rows and cells.
Here’s an example:
let table = document.getElementById("tableId");
let rows = table.rows;
for (let i = 0; i < rows.length; i++) {
let cells = rows[i].cells;
for (let j = 0; j < cells.length; j++) {
console.log(cells[j].innerHTML);
}
}
In this example, the table is selected using document.getElementById("tableId")
and its rows are accessed using table.rows
. The code then loops through each row and accesses its cells using rows[i].cells
. The inner HTML of each cell can then be logged or processed further.
+ There are no comments
Add yours