kor*_*dge 12 node.js web-scraping meteor cheerio
我可以用meteor.js刮掉吗?刚发现cheerio哪种作品非常出色request.我可以将这些用于流星,还是有类似的东西?
你有一个有效的例子吗?
Aks*_*hat 21
当然!很难想象流星不能做什么!首先,您需要一些东西来处理远程http请求.在终端运行的meteor目录中运行meteor add http添加Meteor.http软件包,npm install cheerio(另请参阅另一个关于如何安装npm模块的SO问题,以查看外部npm模块的确切安装位置.
这是一个可能会帮助你的例子,它会刮掉当前时间.
服务器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;
}
});
Run Code Online (Sandbox Code Playgroud)
客户端脚本:
Meteor.call("getTime", function(error, result) {
alert("The current time is " + result);
});
Run Code Online (Sandbox Code Playgroud)
我希望这是有帮助的.在Cheerio中还有其他节点框架,例如node.io