Spaces:
Runtime error
Runtime error
Create evaluator.py
Browse files- src/evaluator.py +37 -0
src/evaluator.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from bs4 import BeautifulSoup
|
| 2 |
+
|
| 3 |
+
def evaluate_html(content):
|
| 4 |
+
score = 0
|
| 5 |
+
feedback = []
|
| 6 |
+
|
| 7 |
+
soup = BeautifulSoup(content, 'html.parser')
|
| 8 |
+
|
| 9 |
+
if soup.html:
|
| 10 |
+
score += 1
|
| 11 |
+
else:
|
| 12 |
+
feedback.append("Missing <html> tag")
|
| 13 |
+
|
| 14 |
+
if soup.head and soup.title:
|
| 15 |
+
score += 1
|
| 16 |
+
else:
|
| 17 |
+
feedback.append("Missing <head> or <title>")
|
| 18 |
+
|
| 19 |
+
if soup.body:
|
| 20 |
+
score += 1
|
| 21 |
+
else:
|
| 22 |
+
feedback.append("Missing <body>")
|
| 23 |
+
|
| 24 |
+
tags = ['p', 'h1', 'href', 'h2', 'img', 'a', 'table']
|
| 25 |
+
used = [tag for tag in tags if soup.find(tag)]
|
| 26 |
+
|
| 27 |
+
if len(used) >= 3:
|
| 28 |
+
score += 1
|
| 29 |
+
else:
|
| 30 |
+
feedback.append("Use at least 3 different HTML tags")
|
| 31 |
+
|
| 32 |
+
if len(soup.text.strip()) > 20:
|
| 33 |
+
score += 1
|
| 34 |
+
else:
|
| 35 |
+
feedback.append("Content too short")
|
| 36 |
+
|
| 37 |
+
return score, feedback
|