无法使用 getElementsByTagName("body")
Unable to use getElementsByTagName("body")
这是我每次 运行 都会出错的代码。我的目标是从 URL 中删除内容,删除所有 HTML 和 return 它:
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. Decent question and answer is available here Python Requests package: Handling xml response。祝你好运!
Zapier 不支持的任何函数都将导致 TypeError。我需要使用正则表达式来实现这一点。
这是我每次 运行 都会出错的代码。我的目标是从 URL 中删除内容,删除所有 HTML 和 return 它:
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. Decent question and answer is available here Python Requests package: Handling xml response。祝你好运!
Zapier 不支持的任何函数都将导致 TypeError。我需要使用正则表达式来实现这一点。