我正在使用一个使用npm软件包(cheerio)的应用程序来抓取Google新闻的首页。
在我的本地计算机上,一切都运行正常,没有错误。但是,当我部署到Meteor.com时,我收到此错误:http://i.imgur.com/4fzMBAf.png
我的应用已部署到http://scrapethenews.meteor.com。
我不明白为什么在Meteor.com上会出现错误,但在本地计算机上却没有。
我还没有完成任何发布/订阅,我还没有实现任何安全功能。
有什么想法吗?
All.js
ScrapedLinks = new Mongo.Collection("scrapedLinks");
if (Meteor.isClient) {
Template.all.helpers({
returnLinks: function() {
return ScrapedLinks.find({}).fetch()
}
})
Template.nav.events({
'click .technology': function() {
var url = 'http://news.google.com/news/section?pz=1&cf=all&ned=us&topic=tc';
Meteor.call('scrapeCat', url, function(error, result) {
console.log(error)
});
ts = ScrapedLinks.find({}).fetch(); for (i = 0; i < (ts.length); i++) {ScrapedLinks.remove({_id: ts[i]._id})
}
}
})
}
Methods.js
Meteor.methods({
scrapeCat: function(url) {
var cheerio = Meteor.npmRequire('cheerio');
var request = Meteor.npmRequire('request');
request(url, Meteor.bindEnvironment(function(error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var i = 0;
$('h2.esc-lead-article-title').filter(function() {
link = $(this).children().attr('href')
var time = moment().format('MMMM Do YYYY, h:mm:ss a')
i = i + 1
if (i < 21) {
ScrapedLinks.insert({
link: link,
title: null,
description: null,
pic: null,
number: i
})
}
})
var f = 0
$('h2.esc-lead-article-title').filter(function() {
title = $(this).children().children().text()
f = f + 1
if (f < 21) {
ScrapedLinks.update({number: f}, {$set: {title: title}})
}
})
var d = 0
$('.esc-lead-snippet-wrapper').filter(function() {
description = $(this).text()
d = d + 1
if (d < 21) {
ScrapedLinks.update({number: d}, {$set: {description: description}})
}
})
var h = 0
$('.esc-thumbnail-image').filter(function() {
var picBefore = $(this).attr('src');
var http = "http:";
var pic = http.concat(picBefore)
h = h + 1
if (h < 21) {
ScrapedLinks.update({number: h}, {$set: {pic: pic}}, console.log('done'))
}
})
} else {
console.log(error)
}}));
}
});
All.html
<template name="all">
<div class="ui three column page grid">
{{#each returnLinks}}
<div class="column">
<div class="ui segment">
<div class="picBox">
<a href="{{link}}">{{title}}</a>
<br />
<br />
<img onerror="this.style.display='none'" src="{{pic}}" /> <br />
<b>{{description}}</b>
</div>
</div>
</div>
{{/each}}
</div>
</template>