I am using routine to return option data from finance.yahoo with help I have managed to get the table data but now I am having getting the latest price. This the HTML data for the part of the site that has the price.
This is the HTML from the website that as one can see has the price
“<” fin-streamer class=“Fw(b) Fz(36px) Mb(-4px) D(ib)” data-symbol=“AAPL” data-test=“qsp-price” data-field=“regularMarketPrice” data-trend=“none” data-pricehint=“2” value=“189.41” active=“”>189.41</fin-streamer">"
It is probably not relevant but the following is the code that gets the table using JavaScript
--GetDataSpecifiedTable
--NOTE:Table count starts at 0
tell application "Safari" to activate -- Wait for Safari
delay 2
-- Execute JavaScript
tell application "Safari"
set secondTableData 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
set RowCnt to count items in secondTableData
log RowCnt
repeat with y from 2 to RowCnt
log item 3 of item y of secondTableData
end repeat
try --Check if Table is for Call options
set CC to item 9 of (reverse of characters of (item 1 of item x of secondTableData))
end try
repeat with x from 2 to count items in secondTableData --Note Row 1 is headings
end repeat
GUI scripting will get me their but has the obvious disadvantage that the position may well move.