What is a good server-side javascript implementation for writing both one-off scripts to handle some task or writing automation scripts to be used over and over.
I am intrigued 开发者_如何学Cby the ability for SSJS to scrape webpages with such ease and am thinking SSJS could replace Python for my generic scripting needs. Is there a SSJS implementation for such things?
If you're familiar with jQuery, then node.js (with the plugins "request", "jsdom", and a port of jquery) let's you easily scrape web pages using jQuery in only a few lines.
The below will print a list of the all the questions on stack overflow's homepage to your console:
// Importing required modules
var request = require("request"),
$ = require("jquery");
request({uri: "http://www.stackoverflow.com/"}, function (err, response, body) {
$(body).find("#question-mini-list h3 a").each(function () {
console.log($(this).text());
});
});
Or if you use another javascript framework in the browser, it's not hard creating your own port of MooTools, Prototype or whatever using jsdom for node.js (it's just a matter of wrapping whatever library to provide it with window
, document
and other global variables - which jsdom
gives you access to).
I'm a fan of node.js. Although its main strength is in building servers (which is apparently not your intention) it is sufficiently versatile and definately worth a look.
I've had good results with Rhino + Quartz
精彩评论