mirror of
https://github.com/tghw/macproxy.git
synced 2024-12-12 13:29:27 +00:00
First pass at the proxy.
This commit is contained in:
commit
43c008917b
20
macify.py
Normal file
20
macify.py
Normal 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
22
proxy.py
Normal 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
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
requests
|
||||
flask
|
Loading…
Reference in New Issue
Block a user