I tried to create a Google Scholar function in Google Sheets that allows you to run Google Scholar searches using predefined search keys and return the number of hits/search results through Google Appscript. However, when I run th script have been encountering the following error:
"TypeError: Cannot read property 'replace' of undefined",
Any idea what I can do to the script to get around the error?
/**
* Returns the "about n results from google scholar"
*
* @param {string} the search query.
* @return {number} the about amount.
* @customfunction
*/
function SCHOLAR(query){
query = query.replace(" ", "+");
const url = `https://scholar.google.com/scholar?hl=en&as_sdt=0%2C5&q=${query}&btnG=`;
const req = UrlFetchApp.fetch(url)
const html = req.getContentText()
const amountText = /<div class="gs\_ab\_mdw">About (.*?) results/gmsi.exec(html)[1]
const amount = Number(amountText.replace(",",""))
return amount
}