Created
July 11, 2013 21:36
-
-
Save sente/5979474 to your computer and use it in GitHub Desktop.
a quick workaround...
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
#!/usr/bin/python | |
import requests | |
import json | |
import sys | |
import lxml | |
import lxml.html | |
url = sys.argv[1] | |
def dostuff(url): | |
resp = requests.get(url) | |
headers = resp.headers | |
content = resp.content | |
root = lxml.html.fromstring(content) | |
root.make_links_absolute(base_url=url) | |
links = root.xpath('//a/@href') | |
imgs = root.xpath('//img/@src') | |
jjj = json.dumps({'headers': headers, | |
'content': content, | |
'links': links, | |
'images': imgs}, | |
indent=2) | |
sys.stdout.write('Access-Control-Allow-Origin: *\r\n') | |
sys.stdout.write("Content-Type: text/javascript\r\n\r\n") | |
sys.stdout.write(jjj) | |
dostuff (url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment