Skip to content

Instantly share code, notes, and snippets.

@mugbya
Last active August 29, 2015 14:09
Show Gist options
  • Save mugbya/54c1b3b22fdf2339518c to your computer and use it in GitHub Desktop.
Save mugbya/54c1b3b22fdf2339518c to your computer and use it in GitHub Desktop.
phantomJS学习代码
console.log('Loading a web page');
var fs = require('fs');
var page = require('webpage').create();
page.open('http://cd.house.qq.com/', function() {
var links = page.evaluate(function() {
var links = new Array();
var len = document.body.getElementsByTagName("object").length;
for( var i = 0; i < len; i++ ){
longHref = document.body.getElementsByTagName("object")[i].nextSibling.getAttribute("href");
links[i] = longHref.substring(0,longHref.indexOf('&'));
}
return links;
});
fs.write('/home/mugbya/oo.txt',links,'w');
for(var i = 0; i < links.length; i++){
var pageS = require('webpage').create();
pageS.open(links[i], (function(i){
return function(){
console.log(i);
};
})(i));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment