Skip to content

Python scraper based on AI

add new get function

VinciGit0086b873f3afda
diff --git a/requirements.txt b/requirements.txt
index 503382fb..200869de 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,7 +1,9 @@
-beautifulsoup4==4.12.3
-langchain==0.1.4
-langchain_core==0.1.16
+langchain==0.1.6
+langchain_community==0.0.19
+langchain_core==0.1.22
langchain_openai==0.0.5
-Requests==2.31.0
-tiktoken==0.5.2
-python-dotenv==1.0.1
\ No newline at end of file
+pytest==8.0.0
+python-dotenv==1.0.1
+setuptools==63.2.0
+tiktoken==0.6.0
+tqdm==4.66.1
diff --git a/yosoai/getter.py b/yosoai/getter.py
index ba6f5f34..5260f1a0 100644
--- a/yosoai/getter.py
+++ b/yosoai/getter.py
@@ -1,54 +1,18 @@
-import requests
+from langchain_community.document_loaders import AsyncHtmlLoader
+from langchain_community.document_transformers import Html2TextTransformer
-HEADERS = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36',
- 'Accept-Language': 'en-US'}
-
-def get_function(link:str, param = HEADERS) -> str:
+def get_function(link:str) -> str:
"""
It sends a GET request to the specified link with optional headers.
Args:
link (str): The URL to send the GET request to.
- param (dict): Optional headers to include in the request. Default is HEADERS.
Returns:
str: The content of the response as a string.
"""
- response = requests.get(url=link, headers=param)
- return str(response.content)
-
-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
+ loader = AsyncHtmlLoader(link)
+ docs = loader.load()
- return res.replace("\\n", "")
\ No newline at end of file
+ html2text = Html2TextTransformer()
+ return str(html2text.transform_documents(docs))
diff --git a/yosoai/request.py b/yosoai/request.py
index 28f75819..2a1fa20b 100644
--- a/yosoai/request.py
+++ b/yosoai/request.py
@@ -38,9 +38,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
- text = remover(text)
-
- messages = truncate_text_tokens(text, model, encoding_name)
+ messages = truncate_text_tokens(text.replace("\\n", ""), model, encoding_name)
processed_messages = 0