Created
February 2, 2014 22:37
-
-
Save edvinasbartkus/8776042 to your computer and use it in GitHub Desktop.
Node: fast HTML parsing with Stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('minreq') || require('request'), | |
WritableStream = require('htmlparser2').WritableStream; | |
var count = 0; | |
var done = function () { | |
console.log('There are ' + count + ' script tags.'); | |
process.exit(1); | |
}; | |
var handlers = { | |
onopentag: function (name, attrs) { | |
if (name == "script") { | |
count += 1; | |
} | |
}, | |
onend: done | |
}; | |
var url = 'http://news.ycombinator.com'; | |
var stream = new WritableStream(handlers, done); | |
request.get(url).pipe(stream); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment