Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions app/controllers/anchorsenseController.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -41,17 +43,16 @@ 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:
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