Skip to content

Instantly share code, notes, and snippets.

@GitHub30
Created July 20, 2015 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GitHub30/0cab50daa217eef99a23 to your computer and use it in GitHub Desktop.
Save GitHub30/0cab50daa217eef99a23 to your computer and use it in GitHub Desktop.
#!/home/werewolf/PhantomJS/phantomjs/bin/phantomjs
var fs = require('fs');
var page = require('webpage').create();
var now = new Date().getTime();
page.onConsoleMessage = function(msg) {
fs.write("data.log", now + "\t" + msg + '\n', 'a');
};
page.open("http://polls.dailynews.yahoo.co.jp/domestic/17822/result", function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
//Heres the actual difference from your code...
var bb = page.evaluate(function () {
var list = ['div.chartBar > p.line > span.total > em',
'div.chartBar > ul > li > div.result > span.number > em',
'div.chartBar > ul > li > div.result > span.value > em',
'div.personalArea > div.profile2type.gender > div > span.ratio > em'];
var ems = document.getElementById('article').querySelectorAll(list.join(','));
var result = [];
for(i=0; i<ems.length; i++)
result.push(ems[i].innerText.replace(',', ''));
console.log(result.join(' '));
return document.getElementById("article").getBoundingClientRect();
});
page.clipRect = {
top: bb.top,
left: bb.left,
width: bb.width,
height: bb.height
};
page.render('image/' + now + '.png');
phantom.exit();
}, 200);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment