Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
});
});
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);
}
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();
function HtmlParser() {
var handler = new htmlparser.DefaultHandler();
var parser = new htmlparser.Parser(handler);
this.parse = function(s) {
parser.parseComplete(s);
};
}
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);
});
});
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);
};
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);
};
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);
}
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']));
}
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);
}
}
});