Xml / HTML strings parameter from Parse.com

I need to parse an XML / HTML file in parse.com cloud code.

I have a string that contains the source code of the html file.

I've already tried several frameworks like jsdom etc., but nothing works in Parse.com-cloudcode environment.

This code, for example, results in an error in the jsdom file. But I have no idea what the real problem is. Because "<" The jsdom.js file has the ">" tags set correctly.

var jsdom = require("cloud/jsdom.js");
var window = jsdom.jsdom().createWindow();
var jquery = require("cloud/jquery-1.11.2.min.js")(window);

var dataHtml = httpResponse.text;

response.success(jquery.$(dataHtml).find("body").text());

      

Mistake:

{"code":141,"error":"Error: Uncaught SyntaxError: Unexpected token \u003c in jsdom.js:5\n    at Object.Parse.Cloud.httpRequest.success (main.js:9:21)

      

Is there any other way to parse a string with XPath or dom in parse.com-cloudcode?

+3


source to share


1 answer


This answer may be too late, but I just figured out the cheerio set of modules that works with Parse.

Example:



var cheerio = require('cloud/cheerio.bundle.js'),
    $ = cheerio.load('<h2 class="title">Hello world</h2>');

$('h2.title').text('Hello there!');
$('h2').addClass('welcome');

$.html();
//=> <h2 class="title welcome">Hello there!</h2>

      

You can get it here .

+6


source







All Articles