Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
re add remover function
VinciGit008a463e949e20
diff --git a/yosoai/getter.py b/yosoai/getter.pyindex 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.pynew file mode 100644index 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 filediff --git a/yosoai/request.py b/yosoai/request.pyindex 9fc97883..31276849 100644--- a/yosoai/request.py+++ b/yosoai/request.py@@ -1,9 +1,9 @@import timefrom tqdm import tqdmfrom typing import List-from multiprocessing import Poolfrom tqdm import tqdmfrom .class_generator import Generator+from .remover import removerfrom .class_creator import create_classfrom .token_calculator import truncate_text_tokens@@ -36,9 +36,7 @@ def send_request(key: str, text:str, values:list[dict], model:str, temperature:fcreate_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