问题
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