node.js - 无法使用 getElementsByTagName ("body")

标签 node.js zapier

这是每次运行时都会导致错误的代码。我的目标是废弃 URL 中的内容,删除所有 HTML,然后返回它:

console.log("Fetching: " + inputData.tweeturl);
fetch(inputData.tweeturl)
  .then(function(res) {
    return res.text();
  }).then(function(body) {
    var rawText = body.getElementsByTagName("body")[0].innerHTML;
    var output = { id: 100, rawHTML: body, rawText: rawText };
    callback(null, output);
  })
  .catch(callback);

问题在于 var rawText = body.getElementsByTagName("body")[0].innerHTML;

我收到的错误是:

Bargle. We hit an error creating a run javascript. :-( Error: TypeError: body.getElementsByTagName is not a function eval (eval at (/var/task/index.js:52:23), :16:24) process._tickDomainCallback (node.js:407:9)

最佳答案

不幸的是 - Zapier 触发器或操作的代码中没有 JS DOM API(这是因为它不在浏览器中运行,并且没有安装必要的库来伪造它)。

你可以看看Python,然后 https://docs.python.org/2/library/xml.etree.elementtree.html 。体面的问题和答案可以在这里找到Python Requests package: Handling xml response 。祝你好运!

关于node.js - 无法使用 getElementsByTagName ("body"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39236318/

相关文章:

node.js - typescript , "process"不存在

javascript - 使用我的浏览器访问本地主机页面但服务器正在运行时出现错误 "str.substr is not a function"?

javascript - 将 NodeJS 回调从导出函数传递到 View

postgresql - 如何将 AWS RDS 安全组中的 Zapier IP 地址列入白名单

javascript - 是否可以在 Zapier 代码中启动服务器

javascript - 如何使用 Zapier 获取 JSON 数组中的第一个值?

node.js - Node/Gulp 与 TFS 构建

node.js - 从 package.json "scripts"部分创建 WebStorm 运行配置

javascript - Zapier 编写的代码 - 用整数分割字符串和带有多个分隔符的文本

json - Zapier Catch (Raw) Hook JSON 解析问题