使用Meteor.js进行抓取 [英] Scraping with Meteor.js

查看:61
本文介绍了使用Meteor.js进行抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以刮一下meteor.js吗?刚刚发现 cheerio 请求结合使用效果很好。我可以将它们与流星一起使用吗?还是有类似的东西?

Can I scrape with meteor.js? Just discovered cheerio which works excellent combined with request. Can I use these with meteor, or is there something similar?

您有一个可行的示例吗?

Do you have an working example?

推荐答案

当然!很难想象流星不能做什么!首先,您需要一些东西来处理远程http请求。在终端的流星目录中,运行 meteor添加http 以添加 Meteor.http 包,也添加 npm install cheerio (请查看以查看确切的位置在哪里安装外部npm模块。

Of course! Its hard to imagine what meteor can't do! First you need something to handle the remote http requests. In your meteor directory in the terminal run meteor add http to add the Meteor.http package, also npm install cheerio (have a look at another SO question on how to install npm modules to see exactly where to install external npm modules.

以下示例可能会对您有所帮助,它会刮除当前时间

Here is an example that might help you out a bit, it scrapes the current time.

服务器js

require = __meteor_bootstrap__.require; //to use npm require must be exposed.
var cheerio = require('cheerio');

Meteor.methods({
    getTime: function () {
        result = Meteor.http.get("http://www.timeanddate.com/worldclock/city.html?n=136");
        $ = cheerio.load(result.content);
        CurrentTime = $('#ct').html();
        return CurrentTime;
    }
});

客户端脚本:

Meteor.call("getTime", function(error, result) {
    alert("The current time is " + result); 
});

我希望这会有所帮助。在Cheerio中,还有其他节点框架,例如node.io

I hope this is helpful. amongst with Cheerio there are also other node frameworks such as node.io

这篇关于使用Meteor.js进行抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆