- Install phantomjs
- run
phantomjs server.js
- run
python pytest.py
-
-
Save slor/5427023 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
# -*- coding: utf-8 -*- | |
import sys | |
import datetime | |
import base64 | |
import requests | |
def main(): | |
input_filename = sys.argv[1] | |
with open(input_filename) as f: | |
html = f.read() | |
payload = {'html': html} | |
response = requests.post('http://localhost:8080/', data=payload) | |
png_bytes = base64.b64decode(response.content) | |
now = datetime.datetime.now().isoformat() | |
filename = 'page_{0}.png'.format(now) | |
with open(filename, 'wb') as f: | |
f.write(png_bytes) | |
print 'Writing to ' + filename | |
if __name__ == '__main__': | |
main() |
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
var SERVER_HOST = '127.0.0.1:8080', | |
server = require('webserver').create(), | |
webpage = require('webpage'), | |
service = server.listen(SERVER_HOST, function(request, response) { | |
var page = webpage.create(), | |
response_content; | |
page.content = request.post.html; | |
response.write(page.renderBase64('PNG')); | |
page.close(); | |
response.close(); | |
}); | |
console.log("Listening to " + SERVER_HOST + " ..."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment