How to use the htmlparser.DefaultHandler function in htmlparser

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 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 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);
}
github makefu / magnets / plugins / soupio.js View on Github external
out.getImages = function getImages(content) { 

    var images = [];

    var handler = new Parse.DefaultHandler(function(err,dom) {
      if (err) {
        log.warn("Error: " +err);
      } else {
        try {
          var ret = Select(dom, 'div[class=imagecontainer]');
          ret.forEach(function (container) {
            //log.debug('found imagecontainer:'+Sys.inspect(container));
            container.children.forEach(function (image) {
              if ( image.name == 'a' ) {
                log.debug('found big image' + image.attribs['href']);
                images.push(Url.resolve(content.url,image.attribs['href']));
              } else if (image.name == 'img') {
                log.debug('found small image' + image.attribs['src']);
                images.push(Url.resolve(content.url,image.attribs['src']));

              }
github makefu / magnets / plugins / cheezburger_network.js View on Github external
out.getImages = function getImages(content) { 
        var images =[];
        var handler = new Parse.DefaultHandler(function(err,dom) {
            //log.debug(Sys.inspect(dom))
            if (err) {
                log.warn("Error: " + err);
            } else {
                ret = Select(dom, 'img[class=event-item-lol-image]');
                try {
                        ret.forEach(function (image){
                            images.push(Url.resolve(content.url,image.attribs['src']));
                        });
                }catch (err) {

                    log.warn("problem with" + content.url +" "+Sys.inspect(ret));
                    log.warn(err);
                }
            }
        });

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