1

Here's the code that results in an error each time I run it. My goal is to scrap the content from the URL, remove all HTML, and return it:

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);

The problem is with var rawText = body.getElementsByTagName("body")[0].innerHTML;

The error I receive is:

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)

Ahmed Sagarwala
  • 400
  • 2
  • 13
  • I do not know `zapier`, but it seems from the stack trace that it just doesn't recognize that function. You can execute client side JS from Node.js with headless browser like Phantom.js, is zapier a equivalent? – DrakaSAN Aug 30 '16 at 20:20
  • Unfortunately, the scripting environment is restricted to only what they offer. Phantom.js or any other npm packages are not possible. – Ahmed Sagarwala Aug 30 '16 at 20:40

2 Answers2

1

Unfortunately - there is no JS DOM API in the Code by Zapier triggers or actions (that is because it isn't run in a browser and doesn't have the necessary libraries installed to fake it).

You might look at Python and instead, and https://docs.python.org/2/library/xml.etree.elementtree.html. Decent question and answer is available here Python Requests package: Handling xml response. Good luck!

Community
  • 1
  • 1
Bryan Helmig
  • 636
  • 4
  • 4
0

Any function not supported by Zapier will result in a TypeError. I needed to use a regular expression to achieve this.

Ahmed Sagarwala
  • 400
  • 2
  • 13