Created
May 10, 2016 09:54
-
-
Save boncheff/bfb58ff4e69fa8a58f2e75514f56a144 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var page = require('webpage').create(); | |
| // for each widget['name'] generate a file with widget['output_file'] as name | |
| var widgets = [ | |
| { | |
| 'name': 'Cloud Summary', | |
| 'output_file': 'cloud_summary.png', | |
| }, | |
| { | |
| 'name': 'Performance Graph', | |
| 'output_file': 'performance_graph.png', | |
| }, | |
| { | |
| 'name': 'Server Power State', | |
| 'output_file': 'server_power_state.png', | |
| }, | |
| { | |
| 'name': 'Servers by Provider', | |
| 'output_file': 'servers_by_provider.png', | |
| }, | |
| ] | |
| // cookies | |
| phantom.addCookie({ | |
| 'name': 'csrf-token', | |
| 'value': 'cookie-value', | |
| 'domain': '.yourdomain' | |
| }) | |
| phantom.addCookie({ | |
| 'name': 'global-session', | |
| 'value': 'cookie-value', | |
| 'domain': '.yourdomain' | |
| }); | |
| page.open('https://page_to_crawl', function() { | |
| window.setTimeout(function() { | |
| widgets.forEach(function(widget) { | |
| name = widget['name']; | |
| var query = "[data-module='" + name + "']" | |
| var clipRect = page.evaluate(function(query) { | |
| return document.querySelector(query).getBoundingClientRect(); | |
| }, query); | |
| page.clipRect = { | |
| 'top': clipRect.top, | |
| 'left': clipRect.left, | |
| 'width': clipRect.width, | |
| 'height': clipRect.height, | |
| }; | |
| page.render(widget['output_file']); | |
| }); | |
| phantom.exit(); | |
| }, 9000); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment