PhantomJS is asynchronous
I got an array of links in the first page,and I need to link each. so I wrote a test. As follows
code :
console.log('Loading a web page');
var page = require('webpage').create();
page.open('http://cd.house.qq.com/', function() {
var ua = page.evaluate(function() {
var link = new Array();
var len = document.body.getElementsByTagName("object").length;
for( var i = 0; i < len; i++ ){
link[i] = document.body.getElementsByTagName("object")[i].nextSibling.getAttribute("href");
}
return link;
});
console.log(ua.length);
page.open(ua[0], function(){
console.log('000000000');
});
page.open(ua[1], function(){
console.log('11111111');
});
});
print :
$ phantomjs p.js
Loading a web page
9
11111111
Q: when Asynchronous, why do not perform array 0