nodejs使用htmlparser2解析html源码成ast示例代码
代码语言:nodejs
所属分类:文件
代码描述:nodejs使用htmlparser2解析html源码成ast示例代码,可解析html的所有标签内容。
代码标签: nodejs htmlparser2 解析 html 源码 ast
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
const htmlparser2= require("htmlparser2"); const parser = new htmlparser2.Parser({ onopentag(name, attributes) { /* * This fires when a new tag is opened. * * If you don't need an aggregated `attributes` object, * have a look at the `onopentagname` and `onattribute` events. */ if (name === "script" && attributes.type === "text/javascript") { console.log("JS! Hooray!"); } }, ontext(text) { /* * Fires whenever a section of text was processed. * * Note that this can fire at any point within text and you might.........完整代码请登录后点击上方下载按钮下载查看
网友评论0