1
我找不到这个函数中的错误。它每次都返回一个空数组。 希望有人能帮助我。函数返回一个空数组
https://gist.github.com/podkopaev/8406346
portal.getHosterByStream = function(stream, callback) {
request(URL + stream, function (error, response, body) {
if (!error && response.statusCode === 200) {
var hoster = [];
var $ = cheerio.load(body);
var information = $('body div[id=frmMain] div[id=dontbeevil] div[id=Vadda]').html();
var items_hoster = $(information).find("ul[id=HosterList]").html();
$(items_hoster).each(function (i, item) {
var rel = $(item).attr('rel');
if (rel != undefined) {
request(MIRROR + rel, function (error, response, body) {
if (!error && response.statusCode === 200) {
var host = JSON.parse(body);
var href = "";
var positionHref = 9;
var i = 0;
while (host.Stream.substr(positionHref + i, 1) != '"') {
href = util.format('%s%s', href, host.Stream.substr(positionHref + i, 1));
i++;
}
hoster.push(href);
} else {
console.log('error second request');
}
});
}
});
callback(hoster);
} else {
console.log('error request page');
}
});
}
可以请你帮助我的代码。我是node.js的新手,现在尝试修复这个bug一个星期。 – deno
@ user3197431我的回答是否帮助您了解代码中的问题? – JohnnyHK
是的,它帮助我了解问题。我试图找到异步库的解决方法,但它不适用于我。 – deno