JSONP python script
I've been playing around with the code (HTML2Canvas) from here: https://github.com/niklasvh/html2canvas
It's a client side Javascript tool to convert a HTML page to a canvas element.
Its uses a proxy to fetch the HTML from a remote site, it makes an Ajax call like this:
$.ajax({
data: {
xhr2:false,
url:urlParts.href
},
url: "http://html2canvas.appspot.com",
dataType: "jsonp",
success: function(html) {
This results in the following, when requesting yahoo.com as the sample URL, url being requested:
http://html2canvas.appspot.com/?callback=jQuery162020564090818326575_1311846010895&xhr2=false&url=http%3A%2F%2Fwww.yahoo.com%2F&_=1311846201150
What I want to do is roll my own JSONP proxy which I can point my copy of the code to. Trouble is I have no i开发者_运维百科dea where to start.
The JSONP that is returned (I won't copy it all) begins like this:
jQuery162020564090818326575_1311846010895("<!DOCTYPE html>\n<html lang=\"en-US\" class=\"y-fp-bg y-fp-pg-grad bkt701\" style=\
So the HTML is escaped and wrapped in a callback.
I'd like to create a Python script that works along the exact same lines and generates the exact same output.
Can anyone point me in the right direction for creating a Python JSONP proxy which would generate similar output? It doesn't have to be Python, I'm just referencing that as it's what is currently used.
I put the source up for the python proxy at https://github.com/niklasvh/html2canvas-proxy. Be warned though, the script will still go through changes which will most likely break the proxy.
精彩评论