Merge branch 'master' into dev

This commit is contained in:
Andres Caicedo
2023-04-10 09:58:13 +02:00
9 changed files with 324 additions and 43 deletions

View File

@@ -7,7 +7,14 @@ cfg = Config()
def scrape_text(url):
"""Scrape text from a webpage"""
response = requests.get(url, headers=cfg.user_agent_header)
# Most basic check if the URL is valid:
if not url.startswith('http'):
return "Error: Invalid URL"
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: