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

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

View File

@ -8,15 +8,16 @@ 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)
url = request.url
resp = session.get(url, 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)
url = request.url
resp = session.post(url, data=request.form, allow_redirects=True)
return macify(resp.content), resp.status_code
if __name__ == '__main__':
app.debug = True
app.run()
app.run(host='0.0.0.0', port=5000)