Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function HtmlParser() {
var handler = new htmlparser.DefaultHandler();
var parser = new htmlparser.Parser(handler);
this.parse = function(s) {
parser.parseComplete(s);
};
}
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);
};
var sys = require("sys");
var htmlparser = require("htmlparser");
var html = "<p>foo</p>";
var handler = new htmlparser.DefaultHandler(function(err, dom) {
if (err)
sys.debug("Error: " + err);
else
sys.debug(sys.inspect(dom, false, null));
}, { enforceEmptyTags: true });
var parser = new htmlparser.Parser(handler);
parser.parseComplete(html);
function parseHtml(html) {
const handler = new htmlparser.DefaultHandler(() => undefined);
const parser = new htmlparser.Parser(handler);
parser.parseComplete(html);
return handler.dom;
}
exports.parse = function(html, options) {
var handler = new htmlparser.DefaultHandler(function() {}, options);
var parser = new htmlparser.Parser(handler);
parser.parseComplete(html.toString());
var dom = handler.dom;
_.each(dom, convert);
return dom;
};