Skip to content

Commit

Permalink
Merge pull request #1588 from arc53/web_loader_fix
Browse files Browse the repository at this point in the history
web loader fix
  • Loading branch information
dartpain authored Jan 20, 2025
2 parents 1ea9b87 + fddee69 commit 3de51b6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions application/parser/remote/web_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from application.parser.remote.base import BaseRemote
from application.parser.schema.base import Document
from langchain_community.document_loaders import WebBaseLoader
from urllib.parse import urlparse

headers = {
"User-Agent": "Mozilla/5.0",
Expand All @@ -23,10 +25,20 @@ def load_data(self, inputs):
urls = [urls]
documents = []
for url in urls:
# Check if the URL scheme is provided, if not, assume http
if not urlparse(url).scheme:
url = "http://" + url
try:
loader = self.loader([url], header_template=headers)
documents.extend(loader.load())
loaded_docs = loader.load()
for doc in loaded_docs:
documents.append(
Document(
doc.page_content,
extra_info=doc.metadata,
)
)
except Exception as e:
print(f"Error processing URL {url}: {e}")
continue
return documents
return documents

0 comments on commit 3de51b6

Please sign in to comment.