Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # htmlparser2
  2. [![NPM version](http://img.shields.io/npm/v/htmlparser2.svg?style=flat)](https://npmjs.org/package/htmlparser2)
  3. [![Downloads](https://img.shields.io/npm/dm/htmlparser2.svg?style=flat)](https://npmjs.org/package/htmlparser2)
  4. [![Build Status](http://img.shields.io/travis/fb55/htmlparser2/master.svg?style=flat)](http://travis-ci.org/fb55/htmlparser2)
  5. [![Coverage](http://img.shields.io/coveralls/fb55/htmlparser2.svg?style=flat)](https://coveralls.io/r/fb55/htmlparser2)
  6. A forgiving HTML/XML/RSS parser. The parser can handle streams and provides a callback interface.
  7. ## Installation
  8. npm install htmlparser2
  9. A live demo of htmlparser2 is available [here](https://astexplorer.net/#/2AmVrGuGVJ).
  10. ## Usage
  11. ```javascript
  12. var htmlparser = require("htmlparser2");
  13. var parser = new htmlparser.Parser({
  14. onopentag: function(name, attribs){
  15. if(name === "script" && attribs.type === "text/javascript"){
  16. console.log("JS! Hooray!");
  17. }
  18. },
  19. ontext: function(text){
  20. console.log("-->", text);
  21. },
  22. onclosetag: function(tagname){
  23. if(tagname === "script"){
  24. console.log("That's it?!");
  25. }
  26. }
  27. }, {decodeEntities: true});
  28. parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>';</ script>");
  29. parser.end();
  30. ```
  31. Output (simplified):
  32. ```
  33. --> Xyz
  34. JS! Hooray!
  35. --> var foo = '<<bar>>';
  36. That's it?!
  37. ```
  38. ## Documentation
  39. Read more about the parser and its options in the [wiki](https://github.com/fb55/htmlparser2/wiki/Parser-options).
  40. ## Get a DOM
  41. The `DomHandler` (known as `DefaultHandler` in the original `htmlparser` module) produces a DOM (document object model) that can be manipulated using the [`DomUtils`](https://github.com/fb55/DomUtils) helper.
  42. The `DomHandler`, while still bundled with this module, was moved to its [own module](https://github.com/fb55/domhandler). Have a look at it for further information.
  43. ## Parsing RSS/RDF/Atom Feeds
  44. ```javascript
  45. new htmlparser.FeedHandler(function(<error> error, <object> feed){
  46. ...
  47. });
  48. ```
  49. Note: While the provided feed handler works for most feeds, you might want to use [danmactough/node-feedparser](https://github.com/danmactough/node-feedparser), which is much better tested and actively maintained.
  50. ## Performance
  51. After having some artificial benchmarks for some time, __@AndreasMadsen__ published his [`htmlparser-benchmark`](https://github.com/AndreasMadsen/htmlparser-benchmark), which benchmarks HTML parses based on real-world websites.
  52. At the time of writing, the latest versions of all supported parsers show the following performance characteristics on [Travis CI](https://travis-ci.org/AndreasMadsen/htmlparser-benchmark/builds/10805007) (please note that Travis doesn't guarantee equal conditions for all tests):
  53. ```
  54. gumbo-parser : 34.9208 ms/file ± 21.4238
  55. html-parser : 24.8224 ms/file ± 15.8703
  56. html5 : 419.597 ms/file ± 264.265
  57. htmlparser : 60.0722 ms/file ± 384.844
  58. htmlparser2-dom: 12.0749 ms/file ± 6.49474
  59. htmlparser2 : 7.49130 ms/file ± 5.74368
  60. hubbub : 30.4980 ms/file ± 16.4682
  61. libxmljs : 14.1338 ms/file ± 18.6541
  62. parse5 : 22.0439 ms/file ± 15.3743
  63. sax : 49.6513 ms/file ± 26.6032
  64. ```
  65. ## How does this module differ from [node-htmlparser](https://github.com/tautologistics/node-htmlparser)?
  66. This is a fork of the `htmlparser` module. The main difference is that this is intended to be used only with node (it runs on other platforms using [browserify](https://github.com/substack/node-browserify)). `htmlparser2` was rewritten multiple times and, while it maintains an API that's compatible with `htmlparser` in most cases, the projects don't share any code anymore.
  67. The parser now provides a callback interface close to [sax.js](https://github.com/isaacs/sax-js) (originally targeted at [readabilitySAX](https://github.com/fb55/readabilitysax)). As a result, old handlers won't work anymore.
  68. The `DefaultHandler` and the `RssHandler` were renamed to clarify their purpose (to `DomHandler` and `FeedHandler`). The old names are still available when requiring `htmlparser2`, your code should work as expected.