Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Parser = require("htmlparser2").WritableStream,
Cornet = require("./"),
minreq = require("minreq"),
$ = require("cheerio");
var cornet = new Cornet();
minreq.get("http://github.com/fb55").pipe(new Parser(cornet));
cornet.remove("script"); //remove all scripts
//show all repos
cornet.select(".repo_list", function(elem){
$(elem).find("h3").each(function(i){
console.log("repo %d: %s", i + 1, $(this).text().trim());
});
});
//does the same
var i = 0;
cornet.select(".repo_list h3", function(elem){
console.log("repo %d: %s", ++i, $(elem).text().trim());
});
return new Promise(resolve => {
let cornet = new Cornet()
let stream = new Readable()
stream.push(body)
stream.push(null)
stream.pipe(new Parser(cornet))
cornet.remove(removeSelector)
cornet.select(elementSelector, parsedBody => {
cornet.removeAllListeners()
cornet = null
resolve(parsedBody)
})
}).timeout(1000, 'Timed out trying to get ' + elementSelector + ' element')
}
if (jsonld.length) {
result.jsonld = jsonld
}
if (microdata.length) {
result.microdata = microdata
}
return resolve(result)
},
onerror (err: Error) {
return reject(err)
}
}
stream.pipe(new WritableStream(cbs, { decodeEntities: true }))
})
return new Promise((resolve, reject) => {
const handler = new Handler(
(err, result) => {
return err ? reject(err) : resolve(result)
},
{
url: contentUrl
}
)
stream.pipe(new WritableStream(handler, { decodeEntities: true }))
})
}