2023-10-11 21:03:40 +00:00
|
|
|
from application.parser.remote.base import BaseRemote
|
2024-05-03 12:55:01 +00:00
|
|
|
from langchain_community.document_loaders import WebBaseLoader
|
|
|
|
|
2024-05-03 13:17:30 +00:00
|
|
|
headers = {
|
|
|
|
"User-Agent": "Mozilla/5.0",
|
|
|
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*"
|
|
|
|
";q=0.8",
|
|
|
|
"Accept-Language": "en-US,en;q=0.5",
|
|
|
|
"Referer": "https://www.google.com/",
|
|
|
|
"DNT": "1",
|
|
|
|
"Connection": "keep-alive",
|
|
|
|
"Upgrade-Insecure-Requests": "1",
|
|
|
|
}
|
|
|
|
|
2023-10-11 21:03:40 +00:00
|
|
|
|
|
|
|
class WebLoader(BaseRemote):
|
|
|
|
def __init__(self):
|
|
|
|
self.loader = WebBaseLoader
|
|
|
|
|
2023-10-13 17:52:56 +00:00
|
|
|
def load_data(self, inputs):
|
2024-02-14 15:17:56 +00:00
|
|
|
urls = inputs
|
2023-10-12 15:40:23 +00:00
|
|
|
if isinstance(urls, str):
|
2024-05-03 12:55:01 +00:00
|
|
|
urls = [urls]
|
2023-10-12 15:40:23 +00:00
|
|
|
documents = []
|
|
|
|
for url in urls:
|
|
|
|
try:
|
2024-05-03 13:17:30 +00:00
|
|
|
loader = self.loader([url], header_template=headers)
|
2023-10-12 15:40:23 +00:00
|
|
|
documents.extend(loader.load())
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Error processing URL {url}: {e}")
|
2024-05-03 12:55:01 +00:00
|
|
|
continue
|
|
|
|
return documents
|