用Parse.com解析xml / HTML字符串 [英] Parse xml/HTML string with Parse.com

查看:127
本文介绍了用Parse.com解析xml / HTML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to parse an XML/HTML file within the cloud-code of parse.com.

我有一个字符串,其中包含源代码html文件。

I've got a string which contains the source-code of the html file.

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

I've already tried multiple frameworks like jsdom etc, but nothing seems to work in the Parse.com-cloudcode environment.

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

This code for example results in an error in the jsdom-file. But I've got no idea what the real problem is. Because the "<" ">" tags are set correctly in the jsdom.js-file.

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)

还有另一种可能性,在解析中用XPath或dom解析字符串。 com-cloudcode?

Is there another possibility to parse a string with XPath or dom in the parse.com-cloudcode?

推荐答案

这个答案可能已经太晚了,但是我刚刚实现了一系列与Parse一起使用的啦啦队模块。

This answer can be too late, but I just realized a bundle of cheerio module that works with Parse.

示例:

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>

您可以获取此处

这篇关于用Parse.com解析xml / HTML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆