我需要在 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());
错误:
{"code":141,"error":"Error: Uncaught SyntaxError: Unexpected token \u003c in jsdom.js:5\n at Object.Parse.Cloud.httpRequest.success (main.js:9:21)
是否有另一种可能在 parse.com-cloudcode 中使用 XPath 或 dom 解析字符串?
最佳答案
这个答案可能为时已晚,但我刚刚发现了一个与 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>
可以得到here .
关于javascript - 使用 Parse.com 解析 xml/HTML 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27908054/