本文介绍了使用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 (请查看。

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进行抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 02:37
查看更多