scrape_text: added tests + hande RequestException

This commit is contained in:
Itamar Friedman
2023-04-10 00:18:37 +03:00
parent 816dc14d82
commit b0cb247b83
2 changed files with 106 additions and 1 deletions

View File

@@ -6,7 +6,10 @@ from llm_utils import create_chat_completion
cfg = Config()
def scrape_text(url):
response = requests.get(url, headers=cfg.user_agent_header)
try:
response = requests.get(url, headers=cfg.user_agent_header)
except requests.exceptions.RequestException as e:
return "Error: " + str(e)
# Check if the response contains an HTTP error
if response.status_code >= 400: