使用Parse.com解析xml/HTML字符串

Chr*_*örz 3 javascript xpath parsing dom parse-platform

我需要在parse.com的云代码中解析XML/HTML文件.

我有一个包含html文件源代码的字符串.

我已经尝试过像jsdom等多个框架,但在Parse.com-cloudcode环境中似乎没有任何工作.

例如,此代码会导致jsdom文件出错.但我不知道真正的问题是什么.因为在<jsdom.js文件中正确设置了"<"">"标签.

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());
Run Code Online (Sandbox Code Playgroud)

错误:

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

是否有另一种可能性在parse.com-cloudcode中解析带有XPath或dom的字符串?

Joh*_*ohn 6

这个答案可能为时已晚,但我刚刚实现了一组与Parse一起使用的cheerio模块.

例:

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>
Run Code Online (Sandbox Code Playgroud)

你可以在这里得到它.