How to use htmlparser - 10 common examples

To help you get started, we’ve selected a few htmlparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pedromtavares / radio / lib / radio.js View on Github external
response.on('end', function() {
      var handler = new htmlparser.DefaultHandler(function (error, dom) {}, {verbose:false,  enforceEmptyTags: true});
      var parser = new htmlparser.Parser(handler);
      parser.parseComplete(rawHtml);
      // yes, this is a major copy and paste, seriously not worth the time to debug this crap
      if (handler.dom[0] && handler.dom[0].children[1] && handler.dom[0].children[1].children[0] && handler.dom[0].children[1].children[0].children[4] && handler.dom[0].children[1].children[0].children[4].children[1] && handler.dom[0].children[1].children[0].children[4].children[1].children[1] && handler.dom[0].children[1].children[0].children[4].children[1].children[1].children[0] && handler.dom[0].children[1].children[0].children[4].children[1].children[1].children[0].children[0] && handler.dom[0].children[1].children[0].children[4].children[1].children[1].children[0].children[0].children[0]){
        var string = handler.dom[0].children[1].children[0].children[4].children[1].children[1].children[0].children[0].children[0].data;
        var index = string.search(/\(.*\)/);
        var listeners = parseInt(string.substr(index+1, 2),10);
        if (listeners > 0){
          listeners -= 1; // one listener is this application itself
        }
        self.streamListeners = listeners;
        callback(listeners,  self.listeners.length);
      }
    });
  });
github andyedinborough / RazorJS / tests / node.js View on Github external
function parseHtml(html, cb){
	var htmlparser = require('htmlparser'),
		select = require('soupselect').select,
		parser = new htmlparser.Parser(new htmlparser.DefaultHandler(function(err, dom) {
			cb(function(selector) {
				return select(dom, selector);
			});
		}));
	parser.parseComplete(html);
}
github fb55 / htmlparser2 / tests / bench.js View on Github external
function HtmlParser() {
        var handler = new htmlparser.DefaultHandler();
        var parser = new htmlparser.Parser(handler);
        this.parse = function(s) {
            parser.parseComplete(s);
        };
    }
github waysact / webpack-subresource-integrity / test / test-webpack.js View on Github external
webpack(webpackConfig, function webpackCallback(err, result) {
      if (err) {
        cleanup();
        callback(err);
      }
      jsIntegrity = result.compilation.assets['bundle.js'].integrity;
      expect(jsIntegrity).toMatch(/^sha/);
      cssIntegrity = result.compilation.assets['styles.css'].integrity;
      expect(cssIntegrity).toMatch(/^sha/);

      handler = new htmlparser.DefaultHandler(function htmlparserCallback(error, dom) {
        if (error) {
          cleanup();
          callback(error);
        } else {
          scripts = select(dom, 'script');
          expect(scripts.length).toEqual(1);
          expect(scripts[0].attribs.crossorigin).toEqual('anonymous');
          expect(scripts[0].attribs.integrity).toEqual(jsIntegrity);

          links = select(dom, 'link');
          expect(links.length).toEqual(1);
          expect(links[0].attribs.crossorigin).toEqual('anonymous');
          expect(links[0].attribs.integrity).toEqual(cssIntegrity);

          cleanup();
          callback();
github fb55 / htmlparser2 / tests / bench.js View on Github external
function HtmlParser() {
        var handler = new htmlparser.DefaultHandler();
        var parser = new htmlparser.Parser(handler);
        this.parse = function(s) {
            parser.parseComplete(s);
        };
    }
github flutter-view / flutter-view / dest / test2.js View on Github external
return yield new Promise(function (resolve, reject) {
            const handler = new htmlparser.DefaultHandler(function (error, dom) {
                if (error)
                    reject(error);
                else
                    resolve(dom);
            }, { verbose: false, ignoreWhitespace: true });
            new htmlparser.Parser(handler).parseComplete(htm);
        });
    });
github macacajs / NoSmoke / lib / crawler / web.js View on Github external
NSCrawler.prototype.beforeExplore = function(source) {
  let raw = source.value.replace(/\n|\r|\\n/gi, '');
  let that = this;
  let handler = new htmlparser.DefaultHandler(function(error, dom) {
    if (error) {
      console.log('parsing error: ' + error);
    } else {
      let target = dom[dom.length - 1].children[dom[dom.length - 1].children.length - 1];
      source.value = target;
      that.explore(source);
    }
  });
  let parser = new htmlparser.Parser(handler);
  parser.parseComplete(raw);
};
github macacajs / NoSmoke / lib / crawler / web.js View on Github external
NSCrawler.prototype.beforeExplore = function(source) {
  let raw = source.value.replace(/\n|\r|\\n/gi, '');
  let that = this;
  let handler = new htmlparser.DefaultHandler(function(error, dom) {
    if (error) {
      console.log('parsing error: ' + error);
    } else {
      let target = dom[dom.length - 1].children[dom[dom.length - 1].children.length - 1];
      source.value = target;
      that.explore(source);
    }
  });
  let parser = new htmlparser.Parser(handler);
  parser.parseComplete(raw);
};
github openwhyd / openwhyd / app / models / htmlDom.js View on Github external
exports.parseHtmlDom = function(html, cb) {
  var parser = new htmlparser.Parser(
    new htmlparser.DefaultHandler(function(error, dom) {
      if (error) {
        console.error(error);
        cb({ error: error });
      } else cb(exports.parseDom(dom));
    })
  );
  parser.parseComplete(html);
};
github themouette / selenium-grid / src / status.js View on Github external
function parseHtml(data, callback) {
    var parser,
        handler = new htmlparser.DefaultHandler(function (error, dom) {
            if (error) {return callback(error);}
            var container, browsers, parsed;
            try {
                container = find(matchBrowserList, dom);
                browsers = find(matchBrowserItem, container);
                parsed = parseItems(browsers);
            } catch (e) {
                return callback(e);
            }
            callback(null, parsed);
        }, { verbose: false, ignoreWhitespace: true });

    parser = new htmlparser.Parser(handler);
    parser.parseComplete(data);
}

htmlparser

Forgiving HTML/XML/RSS Parser in JS for *both* Node and Browsers

MIT
Latest version published 11 years ago

Package Health Score

53 / 100
Full package analysis

Popular htmlparser functions

Similar packages