I'm trying to scrape data from Yahoo Finance into a Google Sheet.
More specifically, this page:
https://finance.yahoo.com/quote/AAPL/key-statistics/
From this page, I'm trying to scrape the value for "Price/Book (mrq)".
So far I've created a Google Sheet, opened Apps Scripts and have the following code:
function yahooF() {
const ticker = 'AAPL';
const url = `https://finance.yahoo.com/quote/AAPL/key-statistics/`;
const res = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
const contentText = res.getContentText();
const Price/Book = contentText.match(/<fin-streamer(?:.*?)active="">(\d+[,]?[\d\.]+?)<\/fin-streamer>/);
console.log(Price/Book[1]);
return Price/Book[1];
}
I'm unable to pull the data, any ideas where I may be going wrong?
I'm hoping the resolution will also teach me how to pull other numbers from that sheet.