shakecities/sites/website.py
Nathan Woodburn 1d1ae251b5
All checks were successful
Build Docker / Build Main Image (push) Successful in 19s
Build Docker / Build SLDs Image (push) Successful in 19s
fix: Less strict sanitation
2023-11-08 23:07:53 +11:00

19 lines
611 B
Python

from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
from bs4 import BeautifulSoup
from lxml.html.clean import clean_html
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_data = str(soup)
return render_template_string(clean_html(modified_data))
except Exception as e:
return "<h1>Invalid HTML</h1><br>" + str(e)