使用服务器端 Javascript 编写脚本
对于编写一次性脚本来处理某些任务或编写要反复使用的自动化脚本,什么是好的服务器端 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您熟悉 jQuery,那么 node.js(带有插件“request”、“jsdom”和 jquery 端口)让您只需几行即可轻松使用 jQuery 抓取网页。
下面将把 stackoverflow 主页上的所有问题打印到你的控制台:
或者,如果你在浏览器中使用另一个 javascript 框架,那么使用 jsdom for node.js 创建你自己的 MooTools、Prototype 或其他端口并不难(只需包装任何库以为其提供
window
、document
和其他全局变量(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:
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 - whichjsdom
gives you access to).我是 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.
我使用 Rhino + Quartz 取得了很好的效果
I've had good results with Rhino + Quartz