0

我正在看这样的东西:

<div class="f00" thing="??" other-thing="???"></div>

我想得到??和 ???我完全被困住了。我尝试获取包含在此周围的 div 中的所有 html,但是在与此相同的级别上还有大量其他代码,因此我只获得了不需要的 html 墙。任何帮助将不胜感激。

4

2 回答 2

0

您可以将jQuery与 node.js 一起使用,它使使用 DOM 变得更加容易。
有了它,你可以做一些事情,比如......

var thing = $('.f00').attr('thing');
var other-thing = $('.f00').attr('other-thing');

查看 jQuery api 以更好地了解它可以做什么......它可以做很多事情。

编辑
你需要安装 jQuery。

npm install jquery

有关如何获取 npm 的说明,请查看此处
有关 node-jquery 的更多信息,请查看github 存储库

希望能帮助到你 :)

于 2013-10-10T06:16:06.583 回答
0

您要查找的包是htmlparser2. 我特别喜欢将它与 一起使用cheerio,它是一种围绕它的包装器,并提供类似 jQuery 的功能。

你会做这样的事情:

$ = cheerio.load(yourHtml);
thing = $('.foo').attr('thing');
otherThing = $('.foo').attr('other-thing');
于 2013-10-10T07:10:26.330 回答