开发者

Node.js & node.io - iterating elements using "each" function stops server

I have a simple function to handle http request and I need to scrap html page from given url. I just copied the example from github. It works, it prints all found attributes but after that it prints "OK: Job complete" and shuts down the server. If I remove the each function, it doesn't stop the server, but I need to use it. Is this some bug in node.io (or in modules it uses) or am I doing something wrong?

function index(response, request){
require('node.io').scrape(function() {
    this.getHtml('http://www.reddit.com/', function(err, $) {
        var stories = [];
        $('a.title').each(function(title) {
            stories.push(title.text);
        });
        this.emit(stories);
    });
});
}

E开发者_StackOverflow社区dit: I've managed to do the job with jsdom, but I'm still wondering about this problem...


Thanks to user "derekdr" on GitHub, the solution for this is described here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜