使用服务器端 Javascript 编写脚本

发布于 2024-10-06 13:58:03 字数 147 浏览 0 评论 0原文

对于编写一次性脚本来处理某些任务或编写要反复使用的自动化脚本,什么是好的服务器端 JavaScript 实现。

我对 SSJS 如此轻松地抓取网页的能力很感兴趣,并且认为 SSJS 可以取代 Python 来满足我的通用脚本需求。有没有 SSJS 实现这样的事情?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

任谁 2024-10-13 13:58:03

如果您熟悉 jQuery,那么 node.js(带有插件“request”、“jsdom”和 jquery 端口)让您只需几行即可轻松使用 jQuery 抓取网页。

下面将把 stackoverflow 主页上的所有问题打印到你的控制台:

// 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());
   });
});

或者,如果你在浏览器中使用另一个 javascript 框架,那么使用 jsdom for node.js 创建你自己的 MooTools、Prototype 或其他端口并不难(只需包装任何库以为其提供 windowdocument 和其他全局变量(jsdom 允许您访问)即可。

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).

失退 2024-10-13 13:58:03

我是 Node.js 的粉丝。尽管它的主要优势在于构建服务器(这显然不是您的意图),但它具有足够的通用性,绝对值得一看。

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.

池予 2024-10-13 13:58:03

我使用 Rhino + Quartz 取得了很好的效果

I've had good results with Rhino + Quartz

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文