You have to use querySelectorAll
instead of querySelector
.
UPDATE
Most country elements do not have links, so you have to just get the td
without the a
tag. Please check the updated code with the updated selector #main_table_countries > tbody:nth-child(2) > tr > td:nth-child(1)
.
To print the values:
const selector = "#main_table_countries > tbody:nth-child(2) > tr > td:nth-child(1)";
document.querySelectorAll(selector).forEach(el => console.log(el.textContent.trim()));
To get an array with the values:
const selector = "#main_table_countries > tbody:nth-child(2) > tr > td:nth-child(1)";
const counties = [...document.querySelectorAll(selector)].map(el => el.textContent.trim());