diff --git a/app/controllers/anchorsenseController.py b/app/controllers/anchorsenseController.py index 3676bf3..e23a5e2 100644 --- a/app/controllers/anchorsenseController.py +++ b/app/controllers/anchorsenseController.py @@ -1,31 +1,33 @@ +import logging from bs4 import BeautifulSoup from typing import List from ..utils.fetcher import fetch_html_with_selenium # This is now async from ..utils.tagfetcher.tagFetcherUtil import get_anchor_tags_from_html from ..lib.anchorsense import analyze_anchor_tag +logger = logging.getLogger(__name__) + async def analyse_anchor_tag(url): - print("fetching html-content") + logger.debug("Fetching HTML content from %s", url) # Await the asynchronous fetch_html_with_selenium function html_content = await fetch_html_with_selenium(url) - print("html content fetched") + logger.debug("HTML content fetched successfully") if html_content is None: - print(f"Failed to fetch HTML content for {url}") + logger.error("Failed to fetch HTML content for %s", url) return [] # Or raise an error, depending on desired behavior - print("retrieving anchor tags") + logger.debug("Retrieving anchor tags from HTML") anchor_tags = get_anchor_tags_from_html(html_content) - print(f"Type of anchor_tags: {type(anchor_tags)}, Length: {len(anchor_tags)}") - print("anchor tag processed") + logger.debug("Found %d anchor tags (type: %s)", len(anchor_tags), type(anchor_tags).__name__) all_issues = [] for anchor_tag in anchor_tags: try: issue_for_tag = analyze_anchor_tag(anchor_tag) all_issues.extend(issue_for_tag) except Exception as e: - print(f"Error analyzing tag: {anchor_tag}, Error: {e}") + logger.exception("Error analyzing anchor tag: %s", anchor_tag) return all_issues @@ -41,10 +43,9 @@ def analyse_anchor_tag_from_html(html_content: str) -> List: Returns: List of issues found in the HTML """ - print("retrieving anchor tags from HTML content") + logger.debug("Retrieving anchor tags from HTML content") anchor_tags = get_anchor_tags_from_html(html_content) - print(f"Type of anchor_tags: {type(anchor_tags)}, Length: {len(anchor_tags)}") - print("anchor tag processed") + logger.debug("Found %d anchor tags (type: %s)", len(anchor_tags), type(anchor_tags).__name__) all_issues = [] for anchor_tag in anchor_tags: @@ -52,6 +53,6 @@ def analyse_anchor_tag_from_html(html_content: str) -> List: issue_for_tag = analyze_anchor_tag(anchor_tag) all_issues.extend(issue_for_tag) except Exception as e: - print(f"Error analyzing tag: {anchor_tag}, Error: {e}") + logger.exception("Error analyzing anchor tag: %s", anchor_tag) return all_issues \ No newline at end of file