sujitv14's picture
Create evaluator.py
e8d17f3 verified
Raw History Blame Contribute Delete
804 Bytes
from bs4 import BeautifulSoup
def evaluate_html(content):
score = 0
feedback = []
soup = BeautifulSoup(content, 'html.parser')
if soup.html:
score += 1
else:
feedback.append("Missing <html> tag")
if soup.head and soup.title:
score += 1
else:
feedback.append("Missing <head> or <title>")
if soup.body:
score += 1
else:
feedback.append("Missing <body>")
tags = ['p', 'h1', 'href', 'h2', 'img', 'a', 'table']
used = [tag for tag in tags if soup.find(tag)]
if len(used) >= 3:
score += 1
else:
feedback.append("Use at least 3 different HTML tags")
if len(soup.text.strip()) > 20:
score += 1
else:
feedback.append("Content too short")
return score, feedback