使用Google Apps脚本UrlFetchApp刮刮Google趋势

问题描述

我正在尝试从以下页面获取前20个趋势:https://trends.google.com/trends/trendingsearches/daily?geo=US使用UrlFetchAppCheerio,但我的divs不断获得以下内容

You are using unsupported browser. Some features may not work correctly. Upgrade to a modern browser,such as Google Chrome.Trends has upgraded to a newer version,which is not supported by this device.dismiss,You are using unsupported browser. Some features may not work correctly. Upgrade to a modern browser,Google apps,Google apps

我尝试将header选项设置为一堆不同的组合,但所有组合均无用。我也尝试使用Postman,结果也一样。

这是我的基本代码

function getSearchTrends(url) {
  var response = UrlFetchApp.fetch(url);
  var status_code = response.getResponseCode();
  if (status_code == 200) {
    var content = response.getContentText();
    const $ = Cheerio.load(content)
    const divs = [];
    
    $('div').each(function(i,elem) {
      divs[i] = $(this).text();
    });
    Logger.log(divs);
  }
}

是否存在某种变通方法来获得有用的HTML响应?谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)