如何使用Axios与Google Apps脚本

biswetbf  于 5个月前  发布在  iOS
关注(0)|答案(1)|浏览(52)

我试图通过网页抓取API的执行网页抓取。对于使用API,它是强制性的,在某种程度上使用axios。现在我无法找到一种方法来使用axios与网页编辑器。
我尝试了给定的方法,代码总是返回null。
1.转到GitHub上的Axios存储库https://github.com/axios/axios
1.单击“releases”选项卡并下载压缩文件形式的库的最新版本。
1.将zip文件解压缩到计算机上的文件夹中。
1.在Google Apps脚本编辑器中,单击左侧边栏中“文件”旁边的“+”图标,创建一个新的脚本文件。
1.将文件命名为“axios.gs“。
1.从步骤3中提取的文件夹中复制“dist/axios.min.js”文件的内容,并将其粘贴到Google Apps脚本编辑器中的“axios.gs“文件中。
1.保存“axios.gs“文件。

const query = 'site:linkedin.com/company "' + 'Company Name' + '"';

  const options = {
    token: "223E9D905C2BC87EBD5181677A8C240A",
    url: 'https://www.google.com/search?q=' + encodeURIComponent(query)
  };

  axios.get("https://scraperbox.com/api/scrape", options)
    .then(response => {
      Logger.log(response.data)
    }).catch(error => {
      Logger.log(error.response.data.errors || error)
    });

字符串

sqougxex

sqougxex1#

我还尝试用axios绕过UrlFetchApp.fetch。我将代码改为:

async function fetchtest(refresh) {
  const url = `https://randomuser.me/api/`
  await axios.get(url)
    .then(response => {
      Logger.log(response)
    }).catch(error => {
      Logger.log(error)
    });
}

字符串
它工作,但我得到了错误:

There is no suitable adapter to dispatch the request since :
- adapter xhr is not supported by the environment
- adapter http is not available in the build


所以XMLHttpRequest不可用,fetch也不可用。来自Node的http也不可用。
ES6没有其他可用的,所以我们被迫使用UrlFetchApp.fetch

相关问题