Gathering detailed insights and metrics for htmlparser
Gathering detailed insights and metrics for htmlparser
Gathering detailed insights and metrics for htmlparser
Gathering detailed insights and metrics for htmlparser
Forgiving HTML/XML/RSS Parser in JS for *both* Node and Browsers
npm install htmlparser
Typescript
Module System
Min. Node Version
NPM Version
99.4
Supply Chain
100
Quality
75.6
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,148 Stars
89 Commits
140 Forks
27 Watchers
3 Branches
7 Contributors
Updated on Apr 08, 2025
Latest Version
1.7.7
Package Id
htmlparser@1.7.7
Size
25.95 kB
NPM Version
1.3.14
Published on
Dec 20, 2013
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
#NodeHtmlParser A forgiving HTML/XML/RSS parser written in JS for both the browser and NodeJS (yes, despite the name it works just fine in any modern browser). The parser can handle streams (chunked data) and supports custom handlers for writing custom DOMs/output.
##Installing
npm install htmlparser
##Running Tests
###Run tests under node: node runtests.js
###Run tests in browser: View runtests.html in any browser
##Usage In Node
1var htmlparser = require("htmlparser"); 2var rawHtml = "Xyz <script language= javascript>var foo = '<<bar>>';< / script><!--<!-- Waah! -- -->"; 3var handler = new htmlparser.DefaultHandler(function (error, dom) { 4 if (error) 5 [...do something for errors...] 6 else 7 [...parsing done, do something...] 8}); 9var parser = new htmlparser.Parser(handler); 10parser.parseComplete(rawHtml); 11sys.puts(sys.inspect(handler.dom, false, null));
##Usage In Browser
1var handler = new Tautologistics.NodeHtmlParser.DefaultHandler(function (error, dom) { 2 if (error) 3 [...do something for errors...] 4 else 5 [...parsing done, do something...] 6}); 7var parser = new Tautologistics.NodeHtmlParser.Parser(handler); 8parser.parseComplete(document.body.innerHTML); 9alert(JSON.stringify(handler.dom, null, 2));
##Example output
1[ { raw: 'Xyz ', data: 'Xyz ', type: 'text' } 2 , { raw: 'script language= javascript' 3 , data: 'script language= javascript' 4 , type: 'script' 5 , name: 'script' 6 , attribs: { language: 'javascript' } 7 , children: 8 [ { raw: 'var foo = \'<bar>\';<' 9 , data: 'var foo = \'<bar>\';<' 10 , type: 'text' 11 } 12 ] 13 } 14, { raw: '<!-- Waah! -- ' 15 , data: '<!-- Waah! -- ' 16 , type: 'comment' 17 } 18]
##Streaming To Parser
1while (...) { 2 ... 3 parser.parseChunk(chunk); 4} 5parser.done();
##Parsing RSS/Atom Feeds
1new htmlparser.RssHandler(function (error, dom) { 2 ... 3});
##DefaultHandler Options
###Usage
1var handler = new htmlparser.DefaultHandler( 2 function (error) { ... } 3 , { verbose: false, ignoreWhitespace: true } 4 );
###Option: ignoreWhitespace Indicates whether the DOM should exclude text nodes that consists solely of whitespace. The default value is "false".
####Example: true
The following HTML:
1<font> 2 <br>this is the text 3<font>
becomes:
1[ { raw: 'font' 2 , data: 'font' 3 , type: 'tag' 4 , name: 'font' 5 , children: 6 [ { raw: 'br', data: 'br', type: 'tag', name: 'br' } 7 , { raw: 'this is the text\n' 8 , data: 'this is the text\n' 9 , type: 'text' 10 } 11 , { raw: 'font', data: 'font', type: 'tag', name: 'font' } 12 ] 13 } 14]
####Example: false
The following HTML:
1<font> 2 <br>this is the text 3<font>
becomes:
1[ { raw: 'font' 2 , data: 'font' 3 , type: 'tag' 4 , name: 'font' 5 , children: 6 [ { raw: '\n\t', data: '\n\t', type: 'text' } 7 , { raw: 'br', data: 'br', type: 'tag', name: 'br' } 8 , { raw: 'this is the text\n' 9 , data: 'this is the text\n' 10 , type: 'text' 11 } 12 , { raw: 'font', data: 'font', type: 'tag', name: 'font' } 13 ] 14 } 15]
###Option: verbose Indicates whether to include extra information on each node in the DOM. This information consists of the "raw" attribute (original, unparsed text found between "<" and ">") and the "data" attribute on "tag", "script", and "comment" nodes. The default value is "true".
####Example: true The following HTML:
1<a href="test.html">xxx</a>
becomes:
1[ { raw: 'a href="test.html"' 2 , data: 'a href="test.html"' 3 , type: 'tag' 4 , name: 'a' 5 , attribs: { href: 'test.html' } 6 , children: [ { raw: 'xxx', data: 'xxx', type: 'text' } ] 7 } 8]
####Example: false The following HTML:
1<a href="test.html">xxx</a>
becomes:
1[ { type: 'tag' 2 , name: 'a' 3 , attribs: { href: 'test.html' } 4 , children: [ { data: 'xxx', type: 'text' } ] 5 } 6]
###Option: enforceEmptyTags Indicates whether the DOM should prevent children on tags marked as empty in the HTML spec. Typically this should be set to "true" HTML parsing and "false" for XML parsing. The default value is "true".
####Example: true The following HTML:
1<link>text</link>
becomes:
1[ { raw: 'link', data: 'link', type: 'tag', name: 'link' } 2, { raw: 'text', data: 'text', type: 'text' } 3]
####Example: false The following HTML:
1<link>text</link>
becomes:
1[ { raw: 'link' 2 , data: 'link' 3 , type: 'tag' 4 , name: 'link' 5 , children: [ { raw: 'text', data: 'text', type: 'text' } ] 6 } 7]
##DomUtils
###TBD (see utils_example.js for now)
##Related Projects
Looking for CSS selectors to search the DOM? Try Node-SoupSelect, a port of SoupSelect to NodeJS: http://github.com/harryf/node-soupselect
There's also a port of hpricot to NodeJS that uses HtmlParser for HTML parsing: http://github.com/silentrob/Apricot
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 4/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More