Skip to content

Python scraper based on AI

Update remover.py

Marco Vinciguerra4703a0b94cbe
diff --git a/scrapegraphai/utils/remover.py b/scrapegraphai/utils/remover.py
index 712b3f78..5b4ff83e 100644
--- a/scrapegraphai/utils/remover.py
+++ b/scrapegraphai/utils/remover.py
@@ -7,8 +7,9 @@ from minify_html import minify
def remover(html_content: str) -> str:
"""
- This function processes HTML content, removes unnecessary tags,
- minifies the HTML, and retrieves the title and body content.
+ This function processes HTML content, removes unnecessary tags
+ (including style tags), minifies the HTML, and retrieves the
+ title and body content.
Parameters:
html_content (str): The HTML content to parse
@@ -23,14 +24,16 @@ def remover(html_content: str) -> str:
title_tag = soup.find('title')
title = title_tag.get_text() if title_tag else ""
- # Script Tag Removal
- [script.extract() for script in soup.find_all('script')]
+ # Script and Style Tag Removal
+ for tag in soup.find_all(['script', 'style']):
+ tag.extract()
# Body Extraction (if it exists)
body_content = soup.find('body')
if body_content:
# Minify the HTML within the body tag
minimized_body = minify(str(body_content))
- return "Title: " + title + ", Body: " + minimized_body
+ return "Title: " + title + ", Body: " + minimized_body
else:
- return "Title: " + title + ", Body: No body content found"
+ return "Title: " + title + ", Body: No body content found"
+