shakecities/sites/website.py
Nathan Woodburn 5ab71b84e0
All checks were successful
Build Docker / Build Main Image (push) Successful in 34s
Build Docker / Build SLDs Image (push) Successful in 35s
fix: Try new sanitization
2023-11-08 23:25:01 +11:00

19 lines
570 B
Python

from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
from bs4 import BeautifulSoup
import bleach
def render(data):
if data == "":
return "No data found for this domain"
try:
soup = BeautifulSoup(data, 'html.parser')
for script in soup.find_all('script'):
script.extract()
modified = str(soup)
return render_template_string(bleach.clean(modified))
except Exception as e:
return "<h1>Invalid HTML</h1><br>" + str(e)