mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-19 23:14:25 +01:00
improve performance and removed code duplication
This commit is contained in:
@@ -5,14 +5,17 @@ from llm_utils import create_chat_completion
|
||||
|
||||
cfg = Config()
|
||||
|
||||
def scrape_text(url):
|
||||
def get_website_content(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: HTTP " + str(response.status_code) + " error"
|
||||
return response
|
||||
|
||||
soup = BeautifulSoup(response.text, "html.parser")
|
||||
|
||||
|
||||
def scrape_text(website_content):
|
||||
soup = BeautifulSoup(website_content.text, "html.parser")
|
||||
|
||||
for script in soup(["script", "style"]):
|
||||
script.extract()
|
||||
@@ -39,14 +42,8 @@ def format_hyperlinks(hyperlinks):
|
||||
return formatted_links
|
||||
|
||||
|
||||
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")
|
||||
def scrape_links(website_content):
|
||||
soup = BeautifulSoup(website_content.text, "html.parser")
|
||||
|
||||
for script in soup(["script", "style"]):
|
||||
script.extract()
|
||||
|
||||
Reference in New Issue
Block a user