문제

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 by 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top