Skip to content

Python scraper based on AI

re add remover function

VinciGit008a463e949e20
diff --git a/yosoai/getter.py b/yosoai/getter.py
index d4d601c7..1f1215de 100644
--- a/yosoai/getter.py
+++ b/yosoai/getter.py
@@ -11,5 +11,4 @@ def get_function(link:str) -> str:
str: The content of the response as a string.
"""
loader = AsyncHtmlLoader(link)
- print(str(loader.load()))
return str(loader.load())
diff --git a/yosoai/remover.py b/yosoai/remover.py
new file mode 100644
index 00000000..27e01eae
--- /dev/null
+++ b/yosoai/remover.py
@@ -0,0 +1,35 @@
+def remover(file:str, only_body:bool = False) -> str:
+ """
+ This function elaborates the HTML file and remove all the not necessary tag
+
+ Parameters:
+ file (str): the file to parse
+
+ Returns:
+ str: the parsed file
+ """
+
+ res = ""
+
+ if only_body == True:
+ isBody = True
+ else:
+ isBody = False
+
+ for elem in file.splitlines():
+ if "<title>" in elem:
+ res = res + elem
+
+ if "<body>" in elem:
+ isBody = True
+
+ if "</body>" in elem:
+ break
+
+ if "<script>" in elem:
+ continue
+
+ if isBody == True:
+ res = res + elem
+
+ return res.replace("\\n", "")
\ No newline at end of file
diff --git a/yosoai/request.py b/yosoai/request.py
index 9fc97883..31276849 100644
--- a/yosoai/request.py
+++ b/yosoai/request.py
@@ -1,9 +1,9 @@
import time
from tqdm import tqdm
from typing import List
-from multiprocessing import Pool
from tqdm import tqdm
from .class_generator import Generator
+from .remover import remover
from .class_creator import create_class
from .token_calculator import truncate_text_tokens
@@ -36,9 +36,7 @@ def send_request(key: str, text:str, values:list[dict], model:str, temperature:f
create_class(values)
time.sleep(2) # TODO: implement asynchronous waiting
- print(text.replace("\\n", ""))
-
- messages = truncate_text_tokens(text, model, encoding_name)
+ messages = truncate_text_tokens(remover(text), model, encoding_name)
processed_messages = 0