【发布时间】:2012-10-30 19:00:06
【问题描述】:
我实际上是在尝试即时抓取页面。当您点击此网址时,它会输出抓取作业的结果。第一次一切都很好。我第二次尝试它(通过 job.options.args 传递不同的参数)它甚至不会执行 node.io 作业的 run() 函数。 scrape_result 第二次返回空(我期待一个对象)。
有什么想法吗?如何确保第二次返回新结果?对于我的抓取工作,我几乎完全使用这里的示例#3:https://github.com/chriso/node.io/wiki/Scraping
scraper.js 的摘录(其余如示例 #3:https://github.com/chriso/node.io/wiki/Scraping)
run: function() {
var book = this.options.args[0].book;
var chapter = this.options.args[0].chapter;
this.getHtml('http://www.url.com' + book + '/' + chapter + '?lang=eng', function(err, $) {
然后是我的 app.js
var scrip_scraper = require('./scraper.js');
app.get('/verses/:book/:chapter', function (req, res) {
var params = {
book: req.param('book'),
chapter: req.param('chapter')
}
scrip_scraper.job.options.args[0] = params;
//scrip_scraper.job.options.args.push(chapter);
console.log(scrip_scraper.job.options.args);
nodeio.start(scrip_scraper, function (err, scrape_result) {
console.log(scrape_result);
}, true);
}); //app.get('/verses/:book/:chapter')
【问题讨论】:
-
我认为为了帮助您,我们需要查看更多您的代码。你是如何创建
scrip_scraper的?我不认为scrip_scraper.job.options.args[0] = params;正在做你想做的事。 -
@Max 我在上面添加了更多代码。我无法弄清楚将参数传递给我的抓取工作的正确方法。使用 options.args[0] 是我能想到的最好的方法。它第一次很好地工作。第二次,run() 似乎没有执行。