SimpleChatTC:SimpleProxy:UrlText: Capture body except for scripts

This commit is contained in:
hanishkvc 2025-10-17 01:39:35 +05:30
parent 45b05df21b
commit f493e1af59
1 changed files with 8 additions and 1 deletions

View File

@ -88,18 +88,25 @@ class TextHtmlParser(html.parser.HTMLParser):
def __init__(self):
super().__init__()
self.bBody = False
self.bCapture = False
self.text = ""
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]):
if tag == 'body':
self.bBody = True
self.bCapture = True
if tag == 'script':
self.bCapture = False
def handle_endtag(self, tag: str):
if tag == 'body':
self.bBody = False
if tag == 'script':
if self.bBody:
self.bCapture = True
def handle_data(self, data: str):
if self.bBody:
if self.bCapture:
self.text += f"{data}\n"