Gathering detailed insights and metrics for html-extractor
Gathering detailed insights and metrics for html-extractor
Gathering detailed insights and metrics for html-extractor
Gathering detailed insights and metrics for html-extractor
npm install html-extractor
Typescript
Module System
Min. Node Version
Node Version
NPM Version
65.9
Supply Chain
98.5
Quality
74.7
Maintenance
100
Vulnerability
99.6
License
CoffeeScript (100%)
Total Downloads
44,742
Last Day
10
Last Week
148
Last Month
673
Last Year
7,752
14 Stars
24 Commits
3 Forks
4 Watching
1 Branches
2 Contributors
Latest Version
0.2.2
Package Id
html-extractor@0.2.2
Size
50.16 kB
NPM Version
2.15.4
Node Version
4.4.6
Cumulative downloads
Total Downloads
Last day
-76.2%
10
Compared to previous day
Last week
8%
148
Compared to previous week
Last month
15.2%
673
Compared to previous month
Last year
10.4%
7,752
Compared to previous year
2
Extract meta-data from a html string. It extracts the body, title, meta-tags and first headlines to a object to push them to a search indexer like elastic-search
npm install html-extractor
1var Extrator = require("html-extractor"); 2var myExtrator = new Extrator();
new Extrator( debug )
arguments
Boolean
optional: default = false
)Call .extract()
to get the data of an html string.
HTML entities will be decoded.
arguments:
String
required )Object
optional )String
required if reduced
is set )String
required if reduced
is set )String
required if reduced
is set )Boobean
default = false
)Function
required )callback arguments:
Error
)null
Object
)String|Array
)reduced.list = true
the body will be an array of all found reduced blocks.Array
)h1
text contents. Including the h1
elements outside the configured reduced elementObject
)<meta content="" name="">
. Other meta tags will be ignored.
String
optional )<meta charset="utf-8" >
is defined it will be returned under data.meta.charset
String
default = ""
)data.meta.title
. Otherwise the key will contain an empty stringString
default = ""
)description
is defined it will be returned under data.meta.description
. Otherwise the key will contain an empty stringArray
default = []
)keywords
is defined it will be returned as trimmed array of strings under data.meta.keywords
. Otherwise the key will contain an empty stringThis is a simple example to extarct the content of a html document
1var Extrator = require("html-extractor"); 2var myExtrator = new Extrator(); 3 4var html = ` 5<html> 6 <head> 7 <title>Testpage</title> 8 </head> 9 <body> 10 <h1>Header 1</h1> 11 <p>Content</p> 12 </body> 13</html> 14` 15 16myExtrator.extract( html, function( err, data ){ 17 if( err ){ 18 throw( err ) 19 } else { 20 console.log( data ); 21 // { 22 // meta: { 23 // title: 'Testpage', 24 // description: '', 25 // keywords: [] 26 // }, 27 // body: ' Header 1 Content ', 28 // h1: [ 'Header 1' ] 29 // } 30 } 31});
see
test/readme_example_simple
or run in Tonic
This is a advanced example to show the usage of the reducing. With the reduce feature it is possible to reduce the body content to the content of a specific html element.
1var Extrator = require("html-extractor"); 2var myExtrator = new Extrator(); 3 4var html = ` 5<html> 6 <head> 7 <title>Super page</title> 8 <meta content="X, Y, Z" name="keywords"> 9 <meta content="Look at this super page" name="description"> 10 <meta content="Super pageCMS" name="generator"> 11 </head> 12 <body> 13 <div id="head"> 14 <h1>My super page<sup>2</sup></h1> 15 </div> 16 <ul id="menu"> 17 <li>Home</li> 18 <li>First</li> 19 <li>Second</li> 20 </ul> 21 <div id="content"> 22 <h1>First article €</h1> 23 <p>Lorem ipsum dolor sit amet ... </p> 24 <h1>Second article ... </h1> 25 <p>Aenean commodo ligula eget dolor.</p> 26 <script> 27 var superVar = [ 3,2,1 ] 28 </script> 29 </div> 30 <section class="abc"> 31 <h3>ABC 1</h3> 32 <p>Lorem ipsum dolor sit amet ... </p> 33 </section> 34 <section class="xyz"> 35 <h3>XYZ 1</h3> 36 <p>Lorem ipsum dolor sit amet ... </p> 37 </section> 38 <section class="abc"> 39 <h3>ABC 2</h3> 40 <p>Lorem ipsum dolor sit amet ... </p> 41 </section> 42 <div id="footer"> 43 Copyright 2013 44 </div> 45 </body> 46</html> 47` 48 49var reduceTo = { 50 tag: "div", 51 attr: "id", 52 val: "content" 53} 54 55myExtrator.extract( html, reduceTo, function( err, data ){ 56 if( err ){ 57 throw( err ) 58 } else { 59 console.log( "String", data ); 60 //{ 61 // meta: { 62 // title: 'Super page', 63 // description: 'Look at this super page', 64 // keywords: ['X', 'Y', 'Z'], 65 // generator: 'Super pageCMS' 66 // }, 67 // body: 'First article € Lorem ipsum dolor sit amet ... Second article ... Aenean commodo ligula eget dolor. ', 68 // h1: ['My super page2', 'First article €', 'Second article ...'] 69 //} 70 } 71}); 72 73var reduceToList = { 74 tag: "div", 75 attr: "id", 76 val: "content", 77 list: true 78}; 79 80myExtrator.extract( html, reduceToList, function( err, data ){ 81 if( err ){ 82 throw( err ) 83 } else { 84 console.log( "List", data ); 85 //{ 86 // meta: { 87 // title: 'Super page', 88 // description: 'Look at this super page', 89 // keywords: ['X', 'Y', 'Z'], 90 // generator: 'Super pageCMS' 91 // }, 92 // body: [ 93 // 'ABC 1 Lorem ipsum dolor sit amet ... ', 94 // 'ABC 2 Lorem ipsum dolor sit amet ... ' 95 // ], 96 // h1: ['My super page2', 'First article', 'Second article'] 97 //} 98 } 99});
see
test/readme_example_advanced
or run in Tonic
html-extractor
is work in progress. Your ideas, suggestions etc. are very welcome.
Version | Date | Description |
---|---|---|
0.2.2 | 2016-07-1 | Fixed trimming when reduced.list is active #3. Thanks to Javier Castro |
0.2.1 | 2016-06-30 | Fixed handling of html entities #1. Thanks to Javier Castro |
0.2.0 | 2016-06-20 | Added option to return reduced elements as list; Fixed reduced value check for classes; Optimized dev env. |
0.1.4 | - | Updated and pinned dependencies and optimized tests |
0.1.3 | - | Fixed extraction to remove style-tag content |
0.1.2 | - | Updated documentation |
0.1.1 | - | Added raw documentation; Fixed travis.yml |
0.1.0 | - | Initial version |
(The MIT License)
Copyright (c) 2016 M. Peter, http://www.tcs.de
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/22 approved changesets -- score normalized to 0
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 2024-12-16
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