Revise tags and get url separately.

This commit is contained in:
Tyler G. Hicks-Wright 2013-12-12 09:13:58 -07:00
parent 43c008917b
commit 8f6a0f4fb1
2 changed files with 7 additions and 6 deletions

View File

@ -1,8 +1,8 @@
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
def macify(html): def macify(html):
soup = BeautifulSoup(html) soup = BeautifulSoup(html)
for tag in soup(['script', 'link', 'style', 'img', 'noscript']): for tag in soup(['script', 'link', 'style', 'noscript']):
tag.extract() tag.extract()
for tag in soup(['div', 'span']): for tag in soup(['div', 'span']):
tag.replaceWithChildren() tag.replaceWithChildren()

View File

@ -8,15 +8,16 @@ session = requests.Session()
@app.route('/', defaults={'path': ''}, methods=['GET']) @app.route('/', defaults={'path': ''}, methods=['GET'])
@app.route('/<path:path>', methods=['GET']) @app.route('/<path:path>', methods=['GET'])
def get(path): def get(path):
resp = session.get(path, params=request.args) url = request.url
resp = session.get(url, params=request.args)
return macify(resp.content), resp.status_code return macify(resp.content), resp.status_code
@app.route('/', defaults={'path': ''}, methods=['POST']) @app.route('/', defaults={'path': ''}, methods=['POST'])
@app.route('/<path:path>', methods=['POST']) @app.route('/<path:path>', methods=['POST'])
def post(path): def post(path):
resp = session.post(path, data=request.form, allow_redirects=True) url = request.url
resp = session.post(url, data=request.form, allow_redirects=True)
return macify(resp.content), resp.status_code return macify(resp.content), resp.status_code
if __name__ == '__main__': if __name__ == '__main__':
app.debug = True app.run(host='0.0.0.0', port=5000)
app.run()