-
Notifications
You must be signed in to change notification settings - Fork 0
/
webAnalyse.py
76 lines (64 loc) · 2.95 KB
/
webAnalyse.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
from bs4 import BeautifulSoup
import re
import csv
def evaluate_website(website_url):
try:
response = requests.get(website_url)
soup = BeautifulSoup(response.content, 'html.parser')
design_score = 5 if soup.find('div', class_='main-container') else 2
functionality_score = 5 if soup.find('form', id='contact-form') else 3
load_time = requests.get(website_url).elapsed.total_seconds()
user_experience_score = 5 if load_time < 3 else 3
meta_tags = soup.find_all('meta', {'name': re.compile(r'keywords|description', re.I)})
seo_score = 5 if len(meta_tags) >= 2 else 3
security_score = 5 if website_url.startswith('https://') else 2
average_score = (design_score + functionality_score + user_experience_score + seo_score + security_score) / 5
return {
'website_url': website_url,
'design_score': design_score,
'functionality_score': functionality_score,
'user_experience_score': user_experience_score,
'seo_score': seo_score,
'security_score': security_score,
'average_score': average_score
}
except Exception as e:
print(f"Ошибка при оценке сайта {website_url}: {e}")
return None
def save_to_csv(results, output_file):
try:
with open(output_file, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['URL', 'Design Score', 'Functionality Score', 'User Experience Score', 'SEO Score', 'Security Score', 'Average Score'])
for result in results:
writer.writerow([
result['website_url'],
result['design_score'],
result['functionality_score'],
result['user_experience_score'],
result['seo_score'],
result['security_score'],
result['average_score']
])
print(f"Результаты сохранены в файл: {output_file}")
except Exception as e:
print(f"Ошибка при сохранении в файл {output_file}: {e}")
if __name__ == "__main__":
csv_input_file = 'schoolsTest.csv'
csv_output_file = 'website_evaluations.csv'
results = []
try:
with open(csv_input_file, newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip header if exists
for row in reader:
website_url = row[0].strip()
evaluation_result = evaluate_website(website_url)
if evaluation_result:
results.append(evaluation_result)
save_to_csv(results, csv_output_file)
except FileNotFoundError:
print(f"Файл {csv_input_file} не найден.")
except Exception as e:
print(f"Произошла ошибка при чтении CSV файла: {e}")