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

标签 javascript parsing dom xpath 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());

错误:

{"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/

相关文章:

javascript - 在列表之间绘制箭头

android - Android环境解析的500KB json文件

c++ - 递归给定文法

javascript - jquery - ajax 加载内容上的日期选择器(颜色选择器等)

javascript - 表格行的叠加

php - 提交和接收ajax表单

python - 正则表达式解析名单输入文件中的键值对

javascript - DocumentFragment 中不允许使用某些元素?

javascript - 如何使用 jQuery 将子级 insideText 与用户输入进行匹配

javascript - Three.js 和 Tween.js 动画链不循环