Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const parse = async (userUrl, paramsObj) => {
const parseHelper = new ParseHelper(userUrl, paramsObj);
userUrl = parseHelper.link;
const opts = {};
if (parseHelper.custom) {
const html = await parseHelper.fetchHtml();
logger(html, 'fixedFetched.html');
opts.html = Buffer.from(html);
}
const extractor = parseHelper.getExtractor();
if (extractor) {
logger(extractor);
Mercury.addExtractor(extractor);
}
let result = await mercury(userUrl, opts);
logger(result.content, 'mercury.html');
let { content } = result;
const preContent = sanitizeHtml(content).trim();
logger(preContent, 'preContent.html');
if (preContent.length === 0) {
const html = await parseHelper.puppet(userUrl);
if (html) {
logger(html, 'asyncContent.html');
result = await mercury(userUrl, { html: Buffer.from(html) });
logger(result.content, 'mercuryAsyncContent.html');
}
}
let { title = '', url: source, iframe } = result;
logger(iframe, 'iframes.html');