Skip to content

Instantly share code, notes, and snippets.

@sente
Created July 11, 2013 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sente/5979474 to your computer and use it in GitHub Desktop.
Save sente/5979474 to your computer and use it in GitHub Desktop.
a quick workaround...
#!/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