initial
This commit is contained in:
commit
74ae93a96e
1 changed files with 94691 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
HTML parser
|
||||
|
||||
- jsdom
|
||||
It's an npm library that can take html as input and let you do things like document.querySelector on it inside of NodeJS without running a sandboxed browser instance
|
||||
- node-html-parser : like jsdom
|
||||
https://www.npmjs.com/package/node-html-parser
|
||||
eg
|
||||
```js
|
||||
import { parse } from 'node-html-parser';
|
||||
|
||||
const root = parse('<ul id="list"><li>Hello World</li></ul>');
|
||||
|
||||
console.log(root.firstChild.structure);
|
||||
// ul#list
|
||||
// li
|
||||
// #text
|
||||
|
||||
console.log(root.querySelector('#list'));
|
||||
// { tagName: 'ul',
|
||||
// rawAttrs: 'id="list"',
|
||||
// childNodes:
|
||||
// [ { tagName: 'li',
|
||||
// rawAttrs: '',
|
||||
// childNodes: [Object],
|
||||
// classNames: [] } ],
|
||||
// id: 'list',
|
||||
// classNames: [] }
|
||||
console.log(root.toString());
|
||||
// <ul id="list"><li>Hello World</li></ul>
|
||||
root.set_content('<li>Hello World</li>');
|
||||
root.toString(); // <li>Hello World</li>
|
||||
```
|
||||
Loading…
Reference in a new issue