我可以使用meteor.js 进行抓取吗?刚刚发现cheerio
结合起来效果很好request
。我可以将它们与流星一起使用吗,或者有类似的东西吗?
你有一个可行的例子吗?
当然!很难想象还有什么是流星做不到的!首先,您需要一些东西来处理远程 http 请求。在终端运行的流星目录中meteor add http
添加Meteor.http
包,还有npm install cheerio
(看一下另一个关于如何安装 npm 模块的问题 https://stackoverflow.com/questions/10587964/where-do-we-put-node-modules-we-install-by-npm-in-a-meteor-project查看安装外部 npm 模块的确切位置。
这是一个可能对您有所帮助的示例,它会刮掉当前时间 http://www.timeanddate.com/worldclock/city.html?n=136.
服务器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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)