removed un necessary changes

This commit is contained in:
pratiksinghchauhan
2023-04-10 12:31:37 +05:30
parent 13467259b4
commit 156739788a
2 changed files with 27 additions and 16 deletions

View File

@@ -5,17 +5,21 @@ from llm_utils import create_chat_completion
cfg = Config()
def get_website_content(url):
response = requests.get(url, headers=cfg.user_agent_header)
def scrape_text(url):
# 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:
return "Error: HTTP " + str(response.status_code) + " error"
return response
def scrape_text(website_content):
soup = BeautifulSoup(website_content.text, "html.parser")
soup = BeautifulSoup(response.text, "html.parser")
for script in soup(["script", "style"]):
script.extract()
@@ -42,8 +46,14 @@ def format_hyperlinks(hyperlinks):
return formatted_links
def scrape_links(website_content):
soup = BeautifulSoup(website_content.text, "html.parser")
def scrape_links(url):
response = requests.get(url, headers=cfg.user_agent_header)
# Check if the response contains an HTTP error
if response.status_code >= 400:
return "error"
soup = BeautifulSoup(response.text, "html.parser")
for script in soup(["script", "style"]):
script.extract()