我有此代码,但无法创建新数组以供进一步使用:
var request = require("request");
var cheerio = require("cheerio");
var pag = [];
request('http://www.tastez.ro/tv.php?query=sopcast', function(error, response, body) {
if (error) {
return console.error('upload failed:', error);
}
var $ = cheerio.load(body);
links = $(".page a"); //use your CSS selector here
$(links).each(function(i, link){
var sop = $(this).attr('href');
pag[i] = sop; //aici pun val gasite in locuri in array
});
pag.push(', ');
});
for (var i=0; i<2; i++){
console.log(pag[i]);
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,它正在列出undefined. 但是如果我把代码写成这样:
var request = require("request");
var cheerio = require("cheerio");
var …Run Code Online (Sandbox Code Playgroud)