After doing some tests with the site you provided and trying different methods I think it will be easier for you to simply retrieve the HTML static site text and then do a Javascript search on the site to return the values you are looking for. The code from the answer I shared is failing because the website has some HTML compatibillity issues as you are trying to interpret that data with XML instead. Moreover, the table you are interested in is within a div
element so you would need to first get to the div
element and then to the table.
The following piece of code with self-explanatory comments returns and logs the Forward P/E
values from the website you provided:
function ALTERNATIVE(){
// Get all the static HTML text of the website
const res = UrlFetchApp.fetch('https://finviz.com/quote.ashx?t=AAPL', {muteHttpExceptions: true}).getContentText();
// Find the index of the string of the parameter we are searching for
index = res.search("Forward P/E");
// create a substring to only get the right number values ignoring all the HTML tags and classes
sub = res.substring(index+68,index+73);
Logger.log(sub);
return sub;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…