How to use the htmlparser2.WritableStream function in htmlparser2

To help you get started, we’ve selected a few htmlparser2 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 fb55 / node-cornet / example.js View on Github external
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());
});
github mix / schenkerian / lib / analyze.js View on Github external
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')
}
github blakeembrey / node-scrappy / src / scrapers / html.ts View on Github external
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 }))
  })
github blakeembrey / node-scrappy / src / scrape / plugins / html.ts View on Github external
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 }))
  })
}