html-parser-n

1.1.4 • Public • Published

html-parse

transform htmlStr to object with Array

npm i htmlstr-parser-n

const { htmlObjParser, htmlStrParser } = require("html-parser-n");
const fs = require("fs");

fs.writeFileSync('./demo.json', JSON.stringify(
  htmlStrParser(`
  <html>
    <body>
      <span id="root" style="color:red;">我是span标签</span>
    </body>
  </html>
`)
))

console.log(htmlObjParser(require("./demo.json")))

结果

{
    "nodeName":"root",
    "children":[
        {
            "nodeName":"html",
            "children":[
                {
                    "nodeName":"body",
                    "children":[
                        {
                            "nodeName":"div",
                            "children":[],
                            "text":"我是div标签"
                        },
                        {
                            "nodeName":"span",
                            "children":[],
                            "id":"root",
                            "style":{
                                "color":"red"
                            },
                            "text":"我是span标签"
                        }
                    ],
                    "text":"  "
                }
            ]
        }
    ]
}

Readme

Keywords

none

Package Sidebar

Install

npm i html-parser-n

Weekly Downloads

3

Version

1.1.4

License

ISC

Unpacked Size

22.6 kB

Total Files

11

Last publish

Collaborators

  • zuolung