Google Script to import data from Google trends

时光毁灭记忆、已成空白 提交于 2021-02-08 09:58:04

问题


just wondering if there is a script to import data from google trends into a google sheet. Basically, I would like to trigger such script daily to know the rising trends for a given topic and I am not sure if there is such solution available.

Else, is there any solution to perform this task?

Many thanks!


回答1:


You may refer with this sample code snippet on how to use Google Apps Script for querying Google trends. For example, this function read input from the spreadsheet and sanitize it, then call up queryGoogleTrends to perform actual query and finally display the actual result:

function startQuery() {
  sheet = SpreadsheetApp.getActiveSpreadsheet();

  // start the query
  var result = buildQueryString(sheet.getRangeByName("q").getValue(),
    sheet.getRangeByName("cat").getValue(),
    sheet.getRangeByName("geo").getValue(),
    sheet.getRangeByName("gprop").getValue(),
    sheet.getRangeByName("cmpt").getValue(),
    sheet.getRangeByName("date").getValue()
                    );

  // display the resulting link in a cell
  sheet.getRangeByName("Query_Result").setValue(result).setBackground("yellow");

  var csv_result = generateCsvDownload(sheet.getRangeByName("q").getValue(),
    sheet.getRangeByName("cat").getValue(),
    sheet.getRangeByName("geo").getValue(),
    sheet.getRangeByName("gprop").getValue(),
    sheet.getRangeByName("cmpt").getValue(),
    sheet.getRangeByName("date").getValue()
                    );

sheet.getRangeByName("CSV_Download_Link").setValue(csv_result).setBackground("yellow");

}


来源:https://stackoverflow.com/questions/51525640/google-script-to-import-data-from-google-trends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!