0
結果應該是60,但它不是,它給輸出20,40,60爲什麼這個JavaScript的結果是重複的?
var request = require("request"),
cheerio = require("cheerio"),
urls = [];
for(var pages =1; pages <=3; pages++){
var target = "http://realestate.com.kh/real-estate-for-sale-in/all/"+pages;
request(target, function(error, response, html){
if(!error && response.statusCode == 200){
var $ = cheerio.load(html);
$(".listing > header > h2 > a").each(function(){
var url = this.attribs.href;
urls.push(url);
});
console.log(urls.length);
}
});
}
有什麼不對?
非常感謝你的傢伙 – july77