MeteorJS给出了一个错误"Exception while simulating the effect of invoking 'code.check' ReferenceError: Scr



我有以下问题。我正在使用MeteorJS为大学创建一个Android程序,该程序应该扫描产品的条形码,然后在下一个站点中显示有关它的信息(营养,盐,糖......)。我正在使用"bobbigmac:scrape-parser"包来抓取 http://www.codecheck.info/网站上带有给定条形码的产品信息。此外,我正在使用"phonegap-plugin-barcodescanner@4.0.2"条形码扫描仪。

但是,我的代码中有一个我找不到的错误。每次扫描条形码时,都会调用"code.check"方法。调用它后,程序总是给出以下错误:

Exception while simulating the effect of invoking 'code.check' ReferenceError: ScrapeParser is not defined(…) ReferenceError: ScrapeParser is not defined
at e (http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:169:27095)
at http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:57:12367
at t.extend.withValue (http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:3:7325)
at a.extend.apply (http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:57:12263)
at Ee [as apply] (http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:143:7640)
at a.extend.call (http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:57:11662)
at Object.e (http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:169:25520)
at http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:87:30879
at http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:87:16577
at http://localhost:12776/103fa376e3004b4c9afacff64c82bba13d4d0f29.js?meteor_js_resource=true:87:31512

奇怪的是,即使有错误,我的程序也能完成方法中的计算并给我正确的结果(80% 的情况)。但是,有时它不会进入该方法,从而给出相同的错误。(20%的案例) 你知道怎么解决吗?这个项目对我来说非常重要,我想我已经尝试了一切修复它但没有成功。 客户端代码:(客户端/主.js)

if (Meteor.isCordova) {
Template.barcode_scanner.events({
'click .scanButton': function (event) {
cordova.plugins.barcodeScanner.scan(
function (result) {
if (confirm("You want to check the product with the following barcode? - " + result.text) == true) {
Meteor.call('code.check', result.text, function(err, result) {
if (result) {
Meteor.call('code.berechnen', result, function(err, score) {
if (score > 75) {
Session.set('classVar', 'progress-bar-success');
} else if (score >= 50 && score <= 75) {
Session.set('classVar', 'progress-bar-warning');
} else {
Session.set('classVar', 'progress-bar-danger');
}       
});
Meteor.call('code.write', result, score, function(err, final) {
Router.go('/ScoreView');
});

}
});
} else {
alert("You pressed Cancel!");
}    

}, 
function (error) {
alert("Scanning failed: " + error);
}
);
}
});
}

服务器代码,方法:(导入/api/tasks.js)

export const list = new Ground.Collection('list', { connection: null });
Meteor.methods({
'code.check'(info) {
console.log('the code is - ' + info);
allInfo = ScrapeParser.get('http://www.codecheck.info/product.search?q='+info);    
ref = allInfo.references[1];
ScrapeParser.registerHelper('toInt', function(str, url) {
return parseInt('0'+str.replace(',', ''));
});
ScrapeParser.registerHelper('titleLinks', function(arr, url) {
return arr && arr.map(function(str) {
var $ = cheerio.load(str);
var link = $('a.title');
return { link: link.attr('href'), title: link.text() };
});
});

ScrapeParser.reset(); // Remove any/all stored parsers
ScrapeParser.parser(ref, {
titles: { path: 'td.c3', content: true, multi: true },
prozent: { path: 'td.c-2', content: true, multi: true },
packung: { path: 'body > div.page.product-info > div.float-group > div.page-col-1-2-left > div.block.prod-basic-info > div > div:nth-child(2) > p:nth-child(2)', content: true, multi: true },
name: { path: 'div.page-title-headline h1', content: true, multi: true },
});

ScrapeParser.resetExcept([ref]); // Remove stored parsers except those in array
values = ScrapeParser.get(ref); 
values.packung[0] = values.packung[0].replace(",", ".");
values.name[0] = values.name[0].trim();
values.titles[4] = values.prozent[0];
values.titles[5] = values.prozent[1];
values.titles[6] = values.prozent[3];
values.titles[7] = values.packung[0];
values.titles[8] = values.name[0];

return values;
},
});
">

code.berechnen"方法只做简单的数学(+/-*)计算,"code.write"将结果保存到GroundDB数据库中。 您可以在此存储库中找到完整的代码:https://github.com/LukasNavickas/meteor-reference-error

如果您想尝试一下,请克隆存储库并尝试在模拟器,Android设备或iOS设备上启动它。

您有任何想法如何修复此错误并在 100% 的情况下获得结果吗?

提前谢谢你!

我认为您不需要这里抓取包的开销。Meteor 有一个内置的 http [1] 模块供您执行请求,并且使用生成的 HTML,您可以使用 cheerio [2] 提取您想要的任何选择器。

免责声明:除了一些内容摘要和标记之外,ScrapeParser的底层库似乎是我的抓取包 [3],它正是这样做的 [4]。但是,我已经有一段时间没有维护该软件包了,并且打开了几个错误报告,因此只需使用几行代码来滚动自己的代码,并从抓取抽象中删除所有可能的问题。

[1] https://themeteorchef.com/snippets/using-the-http-package/#tmc-get-requests

[2] https://github.com/cheeriojs/cheerio

[3] https://github.com/Anonyfox/meteor-scrape

[4] https://github.com/Anonyfox/meteor-scrape/blob/master/lib/parse-website.coffee.md

最新更新