在Node中有PHP的DOM和XPath的替代品吗?
我浏览了一下,似乎DOM和XPath在那里,可以通过NPM包管理器安装,但不确定它们是否正确用于解析HTML和XML?
Is there good alternatives to PHP's DOM and XPath in Node?
I had a look around and it seems DOM and XPath is there and can be installed via NPM package manager but wasn't sure if they are correct ones to be used for parsing HTML and XML?
最满意答案
关于XPath我不确定,但对于HTML,你肯定可以使用cheerio :
var cheerio = require("cheerio"); var $ = cheerio.load(theHTML); if ($(".my-class").is("#my-id")) { console.log("Yay, this element was found!"); }它具有与jQuery相同的语法 - 所以,如果你已经知道如何使用jQuery,你就会知道如何使用cheerio。 作为奖励,cheerio适用于Windows。 JSDOM是许多其他HTML / XML解析器的基础,但却没有。
About XPath I'm not sure, but for HTML, you can surely use cheerio:
var cheerio = require("cheerio"); var $ = cheerio.load(theHTML); if ($(".my-class").is("#my-id")) { console.log("Yay, this element was found!"); }It has the same syntax as jQuery - so, if you do already know how to jQuery, you'll know how to use cheerio. As a bonus, cheerio works on Windows. JSDOM, which is the base for a lot of others HTML/XML parsers, doesn't.
更多推荐
XPath,DOM,NPM,HTML,XML,电脑培训,计算机培训,IT培训"/> <meta name="descri
发布评论