Nodejs替代PHP的DOM和XPath(Nodejs alternatives to PHP's DOM and XPath)

系统教程 行业动态 更新时间:2024-06-14 16:58:30
Nodejs替代PHP的DOM和XPath(Nodejs alternatives to PHP's DOM and XPath)

在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

本文发布于:2023-04-15 03:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/8a19d53e2c3192393815d715eb5c3fd9.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   Nodejs   DOM   alternatives   XPath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!