From 6d796d222dd5ea464f8ca69a87847a00ff31bfd7 Mon Sep 17 00:00:00 2001 From: Torantulino Date: Wed, 29 Mar 2023 09:43:10 +0100 Subject: [PATCH] Adds error check to text scraper. --- AutonomousAI/browse.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AutonomousAI/browse.py b/AutonomousAI/browse.py index ea05421b..361f0cb8 100644 --- a/AutonomousAI/browse.py +++ b/AutonomousAI/browse.py @@ -4,8 +4,14 @@ from bs4 import BeautifulSoup from readability import Document# import openai + def scrape_text(url): response = requests.get(url) + + # Check if the response contains an HTTP error + if response.status_code >= 400: + return "Error: HTTP " + str(response.status_code) + " error" + soup = BeautifulSoup(response.text, "html.parser") for script in soup(["script", "style"]):