File size: 804 Bytes
e8d17f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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