https://github.com/henryluki/html-parser
Simple HTML to JSON parser use Regexp and String.indexOf
https://github.com/henryluki/html-parser
es6 html-parser html-to-json parser
Last synced: about 6 hours ago
JSON representation
Simple HTML to JSON parser use Regexp and String.indexOf
- Host: GitHub
- URL: https://github.com/henryluki/html-parser
- Owner: henryluki
- License: mit
- Created: 2017-03-20T10:24:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-18T06:55:17.000Z (over 7 years ago)
- Last Synced: 2024-03-15T09:56:14.131Z (over 2 years ago)
- Topics: es6, html-parser, html-to-json, parser
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 34
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# html-parser
Simple HTML to JSON parser use Regexp and String.indexOf
## Install
```shell
npm install htmlstr-parser
```
## Basic usage
```javascript
var html = "
"
htmlParser(html)
```
### Output
```javascript
{
"tag": "root",
"children": [{
"type": "Element",
"tagName": "div",
"attributes": {
"style": "height:10rpx;width: 20rpx;"
},
"children": [{
"type": "Text",
"content": "1"
}, {
"type": "Element",
"tagName": "p",
"attributes": {},
"children": [{
"type": "Text",
"content": "2"
}, {
"type": "Element",
"tagName": "br"
}, {
"type": "Element",
"tagName": "a",
"attributes": {
"href": "http://www.baidu.com"
},
"children": [{
"type": "Text",
"content": "3"
}]
}]
}, {
"type": "Element",
"tagName": "p",
"attributes": {},
"children": [{
"type": "Text",
"content": "2"
}]
}]
}]
}
```