I am trying to write a script to access the specific values that are displayed in the following line graph:
Ideally, I want to get the last value (43) from the line graph. For that I tried to run the following sample code:
function W5(){
  var url ='https://trends.google.com/trends/explore?geo=US&q=%2Fm%2F07s_c';  
  var result = UrlFetchApp.fetch(url);
      
  const $ = Cheerio.load(result.getContentText());
  
  Logger.log($);
  return;
}
But it is giving me the following error message, due to which I am unable to parse any data and process it. It's strange because I have not made a single successful request even once but message says too many requests:
Exception: Request failed for https://trends.google.com returned code 429. Truncated server response: Error 429 (Too Many Req... (use muteHttpExceptions option to examine full response)
I followed this solution by changing the parameters according to my requirement:
function startQuery() {
  var sheet = ss.getSheetByName("Sheet2");
  // start the query
  var result = buildQueryString(sheet.getRange("A2").getValue(),
     sheet.getRange("B2").getValue());
  
  // display the resulting link in a cell
  sheet.getRange("C2").setValue(result);
  var csv_result = generateCsvDownload(sheet.getRange("A2").getValue(),
     sheet.getRange("B2").getValue());
  sheet.getRange("D2").setValue(csv_result);
}
function buildQueryString(geo,q) {
  return "http://www.google.com/trends/explore?" +
  "geo=" + encodeURIComponent(geo) +
  "&q=" + encodeURIComponent(q)
  
}
function generateCsvDownload(geo,q) {
  return "http://www.google.com/trends/viz?" +
 "geo=" + encodeURIComponent(geo) +
  "&q=" + encodeURIComponent(q) + 
  "&graph=all_csv";
}
This script takes parameters from the sheet table (starting from Column A):
| geo | q | Query_Result | CSV_Download_Link | csv_result | 
|---|---|---|---|---|
| US | uneployement | 
But it just creates a link instead of actual CSV data output. Any help with that would be much appreciated. Thank you
