这是每次运行时都会导致错误的代码。我的目标是废弃 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/