简体   繁体   English

使用服务器端Javascript编写脚本

[英]Scripting with Server-side Javascript

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. 什么是良好的服务器端javascript实现,用于编写一次性脚本来处理某些任务或编写要反复使用的自动化脚本。

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. 我对SSJS轻松抓取网页的能力很感兴趣,并且我认为SSJS可以替代Python来满足我的通用脚本需求。 Is there a SSJS implementation for such things? 这样的事情是否有SSJS实施?

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. 如果你熟悉jQuery,那么node.js (带有插件“request”,“jsdom”和jquery的端口)让你只需几行就可以轻松地使用jQuery抓取网页。

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). 或者如果你在浏览器中使用另一个javascript框架,那么创建你自己的MooTools,Prototype或其他任何使用jsdom for node.js的端口并不困难(这只是包装任何库以提供windowdocument和其他全局变量的问题) - jsdom允许您访问)。

I'm a fan of node.js. 我是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. 虽然它的主要优势在于构建服务器(显然不是你的意图),但它具有足够的通用性,绝对值得一看。

我在Rhino + Quartz上取得了不错的成绩

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM