Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: Fix web scrape issue with results format #878

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/backend/tools/web_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ async def call(

async def handle_response(self, response: aiohttp.ClientResponse, url: str):
content_type = response.headers.get("content-type")
results = []

# If URL is a PDF, read contents using helper function
if "application/pdf" in content_type:
return {
results.append({
"text": read_pdf(response.content),
"url": url,
}
})
elif "text/html" in content_type:
content = await response.text()
soup = BeautifulSoup(content, "html.parser")
Expand All @@ -98,6 +99,8 @@ async def handle_response(self, response: aiohttp.ClientResponse, url: str):
if title:
data["title"] = title

return data
results.append(data)
else:
raise ValueError(f"Unsupported Content Type using web scrape: {content_type}")

return results
Loading