I have a routine that recovers a table from a website but for some reason it recovers not quite half of the data. The website is finance yahoo and I want recover the last years closing prices for various stocks for analysis. With Safari open to the correct page running the following scrip returns 102 lines the last of which is the line at the bottom of the table. There are about 254 lines. Using Javascript in AppleScript this is the code
tell application "Safari"
set TD to do JavaScript ¬
"var secondTable = document.querySelectorAll('table')[0];
if (secondTable) {var rows = secondTable.getElementsByTagName('tr');
var tableData = [];for (var i = 0; i < rows.length; i++) {var rowData = [];
var cells = rows[i].getElementsByTagName('td');for (var j = 0; j < cells.length; j++) {
rowData.push(cells[j].innerText);}tableData.push(rowData);}tableData;}" in document 1
end tell