First pass at the proxy.

This commit is contained in:
Tyler G. Hicks-Wright 2013-12-12 09:11:34 -07:00
commit 43c008917b
3 changed files with 44 additions and 0 deletions

20
macify.py Normal file
View File

@ -0,0 +1,20 @@
from bs4 import BeautifulSoup
def macify(html):
soup = BeautifulSoup(html)
for tag in soup(['script', 'link', 'style', 'img', 'noscript']):
tag.extract()
for tag in soup(['div', 'span']):
tag.replaceWithChildren()
for tag in soup():
for attr in ['style', 'onclick']:
del tag[attr]
return str(soup)
if __name__ == '__main__':
import requests
html = requests.get('http://stackoverflow.com/questions/5598524/can-i-remove-script-tags-with-beautifulsoup').content
html = macify(html)
with open('macified.html', 'w') as fd:
fd.write(html)

22
proxy.py Normal file
View File

@ -0,0 +1,22 @@
from macify import macify
import requests
from flask import request, Flask
app = Flask(__name__)
session = requests.Session()
@app.route('/', defaults={'path': ''}, methods=['GET'])
@app.route('/<path:path>', methods=['GET'])
def get(path):
resp = session.get(path, params=request.args)
return macify(resp.content), resp.status_code
@app.route('/', defaults={'path': ''}, methods=['POST'])
@app.route('/<path:path>', methods=['POST'])
def post(path):
resp = session.post(path, data=request.form, allow_redirects=True)
return macify(resp.content), resp.status_code
if __name__ == '__main__':
app.debug = True
app.run()

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
requests
flask