shakecities/sites/website.py

20 lines
744 B
Python
Raw Normal View History

from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
2023-11-08 22:51:39 +11:00
from bs4 import BeautifulSoup
2023-11-08 23:04:21 +11:00
import html_sanitizer
def render(data):
2023-11-08 22:32:00 +11:00
if data == "":
return "No data found for this domain"
2023-11-08 22:51:39 +11:00
try:
soup = BeautifulSoup(data, 'html.parser')
for script in soup.find_all('script'):
script.extract()
modified_data = str(soup)
2023-11-08 23:04:21 +11:00
default_settings = dict(html_sanitizer.sanitizer.DEFAULT_SETTINGS)
sanitizer = html_sanitizer.Sanitizer(default_settings)
return render_template_string(str(sanitizer.sanitize(modified_data)))
2023-11-08 22:51:39 +11:00
except Exception as e:
return "<h1>Invalid HTML</h1><br>" + str(e)