from lxml.html.clean import clean_html, Cleaner from fet2020api import fet2020postapi, fet2020memberapi from urllib.parse import urljoin,urlparse import settings fet=fet2020postapi(urljoin(settings.TARGET,"api/posts/")) fetmember=fet2020memberapi(urljoin(settings.TARGET,"api/members/")) def replace_special(t): if type(t)is dict: raise TypeError("String needed git a %s"% str(type(t))) return t.replace("\n","").replace("\r","").replace("\t","").replace("\\","") def strip_html(text): if text=="": return "" c=Cleaner( allow_tags=['i','em','p'], remove_tags=['p','div']) if type(text) is list: h="" for item in text: h=h+" "+strip_html(item)+";" return h print(text) return c.clean_html(replace_special(text))[5:-6]