Last active
March 10, 2017 09:40
-
-
Save firedfox/fbb3e17e419b57308018 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
// example: | |
// phantomjs getComputedStyle.js "http://www.iqiyi.com/" ".usrTxGeneral-box_hover" "position,display,visibility,overflow" | |
var TIMEOUT = 60 * 1000; | |
var webPage = require('webpage'); | |
var system = require('system'); | |
var page = webPage.create(); | |
page.settings.loadImages = false; | |
var args = system.args; | |
if (args.length < 4) { | |
console.log('usage: phantomjs getComputedStyle.js url elementSelector styleNames'); | |
phantom.exit(); | |
} | |
var url = args[1]; | |
var elementSelector = args[2]; | |
var styleNames = args[3].split(','); | |
var getStyles = function(status) { | |
var styleValues = page.evaluate(function(elementSelector, styleNames) { | |
var element = document.querySelector(elementSelector); | |
var computedStyle = window.getComputedStyle(element); | |
var styleValues = []; | |
styleNames.forEach(function(styleName) { | |
styleValues.push(computedStyle.getPropertyValue(styleName)); | |
}); | |
return styleValues; | |
}, elementSelector, styleNames); | |
console.log(styleValues.join('\t')); | |
phantom.exit(); | |
}; | |
page.open(url, getStyles); | |
setTimeout(getStyles, TIMEOUT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment