Skip to content

Instantly share code, notes, and snippets.

@slor
Forked from garrypolley/ch.html
Last active December 16, 2015 11:19
Show Gist options
  • Save slor/5427023 to your computer and use it in GitHub Desktop.
Save slor/5427023 to your computer and use it in GitHub Desktop.
# -*- 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()
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 + " ...");

Trying this out

  • Install phantomjs
  • run phantomjs server.js
  • run python pytest.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment