Created
March 29, 2014 08:07
-
-
Save vimagick/9850553 to your computer and use it in GitHub Desktop.
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
fs = require('fs'); | |
page = require('webpage').create(); | |
url = 'http://stackoverflow.com/users/348785/kev'; | |
cjf = '/Users/kev/cookies.txt'; | |
function load_cookies(cjf){ | |
f = fs.open(cjf, 'r'); | |
while(!f.atEnd()){ | |
line = f.readLine(); | |
fields = line.split('\t'); | |
if(fields.length!=8) | |
continue; | |
cookie = { | |
'name': fields[6], | |
'value': fields[7], | |
'domain': fields[0], | |
'path': fields[2], | |
} | |
phantom.addCookie(cookie); | |
} | |
} | |
load_cookies(cjf); | |
page.open(url, function(status){ | |
obj = page.evaluate(function(){ | |
obj = {}; | |
tbl = document.querySelectorAll('div.gravatar ~ div.data tr'); | |
for(i=0;i<tbl.length;i++){ | |
e = tbl[i]; | |
k = e.querySelector('td:first-of-type').textContent.trim(); | |
v = e.querySelector('td:last-of-type').textContent.trim(); | |
obj[k] = v; | |
} | |
return obj; | |
}); | |
console.log(JSON.stringify(obj)); | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment