Last active
August 29, 2015 14:09
-
-
Save mugbya/54c1b3b22fdf2339518c to your computer and use it in GitHub Desktop.
phantomJS学习代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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