Spaces:
Running
Running
File size: 932 Bytes
0f93e9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import requests
from bs4 import BeautifulSoup
from langchain_community.document_loaders import WebBaseLoader
from langchain_core.documents import Document
from config.constants import URLS
def load_documents():
"""Загрузка документов с веб-сайта"""
documents = []
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
}
for url in URLS:
try:
loader = WebBaseLoader(
web_paths=[url],
header_template=headers
)
docs = loader.load()
if docs:
documents.extend(docs)
print(f"Загружено {url}: {len(docs)} документов")
except Exception as e:
print(f"Ошибка загрузки {url}: {str(e)}")
return documents |