File size: 27,643 Bytes
a3acd70 81169a3 a3acd70 b43f4c5 a3acd70 b43f4c5 a3acd70 81169a3 a3acd70 77dc14b b43f4c5 77dc14b b43f4c5 77dc14b a3acd70 77dc14b a3acd70 77dc14b a3acd70 77dc14b a3acd70 77dc14b a3acd70 77dc14b 81169a3 a3acd70 77dc14b a3acd70 77dc14b 0799651 77dc14b a3acd70 77dc14b a3acd70 b43f4c5 12a11fb 77dc14b 12a11fb 77dc14b 12a11fb 77dc14b 81169a3 a3acd70 77dc14b a3acd70 77dc14b 7e9a98f 77dc14b 7e9a98f 77dc14b 81169a3 6887cab 77dc14b 7e9a98f 77dc14b 7e9a98f 77dc14b 6887cab 77dc14b 6887cab 77dc14b 6887cab 81169a3 7e9a98f 77dc14b 7e9a98f 77dc14b 7e9a98f 77dc14b 7e9a98f 81169a3 77dc14b 81169a3 77dc14b 81169a3 77dc14b 7e9a98f 77dc14b 81169a3 77dc14b 7e9a98f 81169a3 77dc14b 81169a3 77dc14b 81169a3 77dc14b 81169a3 1148762 81169a3 77dc14b 81169a3 77dc14b 81169a3 77dc14b 81169a3 77dc14b 81169a3 77dc14b 81169a3 77dc14b 81169a3 77dc14b 0a285a8 81169a3 77dc14b 7e9a98f 81169a3 77dc14b 7e9a98f 81169a3 77dc14b 7e9a98f 81169a3 |
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
import streamlit as st
from streamlit_lottie import st_lottie
from streamlit_option_menu import option_menu
import requests
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime
import httpx
import asyncio
import aiohttp
from bs4 import BeautifulSoup
import whois
import ssl
import socket
import dns.resolver
from urllib.parse import urlparse
import json
import numpy as np
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from PIL import Image
import io
import time
import matplotlib.pyplot as plt
import seaborn as sns
# تحسين مظهر الصفحة
st.set_page_config(
layout="wide",
page_title="محلل المواقع المتقدم | Website Analyzer Pro",
page_icon="🔍",
initial_sidebar_state="expanded"
)
# تحسين التصميم باستخدام CSS
st.markdown("""
<style>
/* تخصيص الخلفية والألوان */
.main {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
padding: 20px;
}
/* تنسيق البطاقات */
.metric-card {
background: white;
border-radius: 15px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
.metric-card:hover {
transform: translateY(-5px);
}
/* تنسيق الأزرار */
.stButton>button {
background: linear-gradient(45deg, #2196F3, #21CBF3);
color: white;
border-radius: 25px;
padding: 15px 25px;
border: none;
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
transition: all 0.3s ease;
}
.stButton>button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
/* تنسيق العناوين */
h1, h2, h3 {
color: #1E3D59;
font-family: 'Tajawal', sans-serif;
}
/* تنسيق المدخلات */
.stTextInput>div>div>input {
border-radius: 10px;
border: 2px solid #E0E0E0;
padding: 10px;
}
/* تنسيق التوسيعات */
.streamlit-expanderHeader {
background-color: white;
border-radius: 10px;
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap" rel="stylesheet">
""", unsafe_allow_html=True)
# تحسين تحميل الرسوم المتحركة
# تحسين تحميل الرسوم المتحركة
def load_lottieurl(url):
try:
r = requests.get(url)
if r.status_code == 200:
return r.json()
except Exception as e:
print(f"Error loading Lottie animation: {e}")
# محتوى Lottie احتياطي بسيط
return {
"v": "5.5.7",
"fr": 60,
"ip": 0,
"op": 180,
"w": 512,
"h": 512,
"nm": "Loading Animation",
"ddd": 0,
"assets": [],
"layers": [{
"ddd": 0,
"ind": 1,
"ty": 4,
"nm": "Circle",
"sr": 1,
"ks": {
"o": {"a": 0, "k": 100},
"r": {
"a": 1,
"k": [{
"i": {"x": [0.833], "y": [0.833]},
"o": {"x": [0.167], "y": [0.167]},
"t": 0,
"s": [0]
}, {
"t": 180,
"s": [360]
}]
},
"p": {"a": 0, "k": [256, 256, 0]},
"a": {"a": 0, "k": [0, 0, 0]},
"s": {"a": 0, "k": [100, 100, 100]}
},
"ao": 0,
"shapes": [{
"ty": "gr",
"it": [{
"ty": "rc",
"d": 1,
"s": {"a": 0, "k": [100, 100]},
"p": {"a": 0, "k": [0, 0]},
"r": {"a": 0, "k": 50}
}],
"nm": "Rectangle",
"np": 2,
"cix": 2,
"bm": 0,
"ix": 1,
"mn": "ADBE Vector Group",
"hd": false
}],
"ip": 0,
"op": 180,
"st": 0,
"bm": 0
}]
}
# تحديث روابط الرسوم المتحركة لتكون أكثر موثوقية
lottie_analyzing = load_lottieurl("https://lottie.host/2c271015-5ef5-443c-9c4a-06ac803571fd/xEFNOVJ1lL.json")
lottie_success = load_lottieurl("https://lottie.host/cafd92b4-3389-441d-8b7c-ad0e178c870c/xYJdvN5QVb.json")
lottie_error = load_lottieurl("https://lottie.host/f93ea5d8-4452-4c7a-8965-4b3ccb28661c/H6l1LgXKrK.json")
# اضافة التحقق قبل استخدام الرسوم المتحركة
def show_lottie_animation(lottie_data, height=200):
if lottie_data:
st_lottie(lottie_data, height=height)
else:
st.warning("Could not load animation")
class WebsiteAnalyzer:
def __init__(self):
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
async def analyze_performance(self, url):
try:
start_time = time.time()
async with httpx.AsyncClient() as client:
response = await client.get(url)
load_time = time.time() - start_time
page_size = len(response.content) / 1024
# تحليل محسن للأداء
performance_metrics = {
"load_time": round(load_time, 2),
"page_size": round(page_size, 2),
"status_code": response.status_code,
"تقدير السرعة": self._estimate_speed(load_time),
"عدد الزيارات التقريبي": self._estimate_traffic(url),
"ترتيب الموقع على جوجل": self._estimate_google_rank(url),
"السعر التقريبي للموقع": self._estimate_website_value(url),
"تقييم الأداء": self._calculate_performance_score(load_time, page_size),
"توصيات تحسين الأداء": self._get_performance_recommendations(load_time, page_size)
}
return performance_metrics
except Exception as e:
return {"error": f"خطأ في تحليل الأداء: {str(e)}"}
def _calculate_performance_score(self, load_time, page_size):
score = 100
if load_time > 2:
score -= (load_time - 2) * 10
if page_size > 1000:
score -= (page_size - 1000) / 100
return max(0, min(100, round(score)))
def _get_performance_recommendations(self, load_time, page_size):
recommendations = []
if load_time > 2:
recommendations.append("تحسين سرعة تحميل الصفحة")
if page_size > 1000:
recommendations.append("تقليل حجم الصفحة")
return recommendations if recommendations else ["أداء الموقع جيد!"]
async def analyze_seo(self, url):
try:
async with httpx.AsyncClient() as client:
response = await client.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# تحليل SEO محسن
seo_analysis = {
"العنوان": self._analyze_title(soup),
"الوصف": self._analyze_description(soup),
"الكلمات المفتاحية": self._analyze_keywords(soup),
"هيكل العناوين": self._analyze_headings(soup),
"الروابط": self._analyze_links(soup),
"الصور": self._analyze_images(soup),
"تقييم SEO الإجمالي": self._calculate_seo_score(soup)
}
return seo_analysis
except Exception as e:
return {"error": f"خطأ في تحليل SEO: {str(e)}"}
def _analyze_title(self, soup):
title = soup.title.string if soup.title else ""
return {
"النص": title,
"الطول": len(title) if title else 0,
"التقييم": "ممتاز" if title and 30 <= len(title) <= 60 else "يحتاج تحسين",
"التوصيات": self._get_title_recommendations(title)
}
def _get_title_recommendations(self, title):
recommendations = []
if not title:
recommendations.append("إضافة عنوان للصفحة")
elif len(title) < 30:
recommendations.append("زيادة طول العنوان")
elif len(title) > 60:
recommendations.append("تقليل طول العنوان")
return recommendations if recommendations else ["العنوان مثالي!"]
def analyze_security(self, url):
try:
domain = urlparse(url).netloc
security_analysis = {
"شهادة SSL": self._analyze_ssl(url),
"سجلات DNS": self._analyze_dns(domain),
"تقييم الحماية": self._calculate_security_score(url),
"توصيات الأمان": self._get_security_recommendations(url)
}
return security_analysis
except Exception as e:
return {"error": f"خطأ في تحليل الأمان: {str(e)}"}
def _analyze_ssl(self, url):
try:
context = ssl.create_default_context()
with socket.create_connection((urlparse(url).netloc, 443)) as sock:
with context.wrap_socket(sock, server_hostname=urlparse(url).netloc) as ssock:
cert = ssock.getpeercert()
return {
"الحالة": "آمن ✅",
"تاريخ الانتهاء": cert['notAfter'],
"مُصدر الشهادة": cert['issuer'][0][0][1]
}
except:
return {"الحالة": "غير آمن ❌", "توصية": "تثبيت شهادة SSL"}
def generate_reports(self, performance_data, seo_data, security_data):
# إنشاء تقارير تفصيلية
fig = plt.figure(figsize=(15, 10))
# رسم بياني للأداء
plt.subplot(2, 2, 1)
performance_scores = [
performance_data.get('تقييم الأداء', 0),
seo_data.get('تقييم SEO الإجمالي', 0),
security_data.get('تقييم الحماية', 0)
]
plt.bar(['الأداء', 'SEO', 'الأمان'], performance_scores)
plt.title('تقييم شامل للموقع')
# تحويل الرسم البياني إلى صورة
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
return Image.open(buf)
def main():
st.title("🔍 محلل المواقع المتقدم")
# القائمة الجانبية المحسنة
with st.sidebar:
selected = option_menu(
menu_title="القائمة الرئيسية",
options=["تحليل جديد", "التقارير السابقة", "الإحصائيات", "الإعدادات"],
icons=["search", "file-text", "graph-up", "gear"],
menu_icon="cast",
styles={
"container": {"padding": "15px"},
"icon": {"color": "orange", "font-size": "25px"},
"nav-link": {"font-size": "16px", "text-align": "right", "margin": "0px"}
}
)
if selected == "تحليل جديد":
col1, col2 = st.columns([2, 1])
with col1:
url = st.text_input("🌐 أدخل رابط الموقع", "https://example.com")
analyze_button = st.button("⚡ بدء التحليل")
if analyze_button:
with st.spinner("جاري التحليل... ⏳"):
st_lottie(lottie_analyzing, height=200)
analyzer = WebsiteAnalyzer()
# تحليل متزامن
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
performance_data = loop.run_until_complete(analyzer.analyze_performance(url))
seo_data = loop.run_until_complete(analyzer.analyze_seo(url))
security_data = analyzer.analyze_security(url)
# عرض النتائج بشكل جذاب
st.success("✨ تم اكتمال التحليل بنجاح!")
# بطاقات إحصائية محسنة
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric(
"⚡ سرعة التحميل",
f"{performance_data.get('load_time', 'N/A')}s",
delta="-0.2s"
)
with col2:
st.metric(
"👥 الزيارات الشهرية",
f"{performance_data.get('عدد الزيارات التقريبي', 'N/A'):,}",
delta="↑ 12%"
)
with col3:
st.metric(
"🎯 ترتيب جوجل",
f"#{performance_data.get('ترتيب الموقع على جوجل', 'N/A')}",
delta="↑ 5"
)
with col4:
st.metric(
"💰 القيمة التقديرية",
f"${performance_data.get('السعر التقريبي للموقع', 'N/A'):,}",
delta="↑ $1,000"
)
# تقارير تفصيلية
tabs = st.tabs(["📊 الأداء", "🎯 SEO", "🔒 الأمان", "📈 التقرير الشامل"])
with tabs[0]:
st.subheader("تحليل الأداء التفصيلي")
# رسم بياني للأداء
performance_fig = go.Figure()
# إضافة مؤشر سرعة التحميل
performance_fig.add_trace(go.Indicator(
mode = "gauge+number",
value = performance_data.get('تقييم الأداء', 0),
title = {'text': "تقييم الأداء العام"},
gauge = {
'axis': {'range': [0, 100]},
'steps': [
{'range': [0, 50], 'color': "lightgray"},
{'range': [50, 75], 'color': "gray"},
{'range': [75, 100], 'color': "darkblue"}
],
'bar': {'color': "royalblue"}
}
))
st.plotly_chart(performance_fig, use_container_width=True)
# جدول تفصيلي للأداء
st.markdown("""
<div class="metric-card">
<h3>📊 تفاصيل الأداء</h3>
""", unsafe_allow_html=True)
perf_cols = st.columns(2)
with perf_cols[0]:
st.markdown(f"""
- ⚡ زمن التحميل: {performance_data.get('load_time')}s
- 📦 حجم الصفحة: {performance_data.get('page_size')} KB
- 🎯 تقدير السرعة: {performance_data.get('تقدير السرعة')}
""")
with perf_cols[1]:
st.markdown(f"""
- 👥 الزيارات الشهرية: {performance_data.get('عدد الزيارات التقريبي'):,}
- 🌐 حالة الموقع: {performance_data.get('status_code')}
- 💰 القيمة التقديرية: ${performance_data.get('السعر التقريبي للموقع'):,}
""")
with tabs[1]:
st.subheader("تحليل SEO")
# مخطط رادار لتقييم SEO
seo_scores = {
'العنوان': seo_data.get('العنوان', {}).get('التقييم', 0),
'الوصف': seo_data.get('الوصف', {}).get('التقييم', 0),
'الكلمات المفتاحية': seo_data.get('الكلمات المفتاحية', {}).get('التقييم', 0),
'الروابط': seo_data.get('الروابط', {}).get('التقييم', 0),
'الصور': seo_data.get('الصور', {}).get('التقييم', 0)
}
seo_fig = go.Figure(data=go.Scatterpolar(
r=list(seo_scores.values()),
theta=list(seo_scores.keys()),
fill='toself'
))
seo_fig.update_layout(
polar=dict(
radialaxis=dict(visible=True, range=[0, 100])
),
showlegend=False
)
st.plotly_chart(seo_fig, use_container_width=True)
# بطاقات تحليل SEO
seo_cols = st.columns(3)
with seo_cols[0]:
st.markdown("""
<div class="metric-card">
<h4>🎯 تحليل العنوان</h4>
""", unsafe_allow_html=True)
st.write(seo_data.get('العنوان', {}))
with seo_cols[1]:
st.markdown("""
<div class="metric-card">
<h4>📝 تحليل الوصف</h4>
""", unsafe_allow_html=True)
st.write(seo_data.get('الوصف', {}))
with seo_cols[2]:
st.markdown("""
<div class="metric-card">
<h4>🔍 الكلمات المفتاحية</h4>
""", unsafe_allow_html=True)
st.write(seo_data.get('الكلمات المفتاحية', {}))
with tabs[2]:
st.subheader("تحليل الأمان")
# مؤشر الأمان العام
security_score = security_data.get('تقييم الحماية', 0)
security_fig = go.Figure(go.Indicator(
mode = "gauge+number+delta",
value = security_score,
delta = {'reference': 90},
title = {'text': "مستوى الأمان العام"},
gauge = {
'axis': {'range': [0, 100]},
'steps': [
{'range': [0, 50], 'color': "red"},
{'range': [50, 75], 'color': "yellow"},
{'range': [75, 100], 'color': "green"}
]
}
))
st.plotly_chart(security_fig, use_container_width=True)
# تفاصيل الأمان
security_cols = st.columns(3)
with security_cols[0]:
st.markdown("""
<div class="metric-card">
<h4>🔒 شهادة SSL</h4>
""", unsafe_allow_html=True)
st.write(security_data.get('شهادة SSL', {}))
with security_cols[1]:
st.markdown("""
<div class="metric-card">
<h4>🌐 سجلات DNS</h4>
""", unsafe_allow_html=True)
st.write(security_data.get('سجلات DNS', {}))
with security_cols[2]:
st.markdown("""
<div class="metric-card">
<h4>⚡ توصيات الأمان</h4>
""", unsafe_allow_html=True)
st.write(security_data.get('توصيات الأمان', []))
with tabs[3]:
st.subheader("التقرير الشامل")
# إنشاء تقرير PDF
if st.button("📥 تحميل التقرير الشامل (PDF)"):
report_data = {
'url': url,
'date': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'performance': performance_data,
'seo': seo_data,
'security': security_data
}
# هنا يمكن إضافة كود لإنشاء ملف PDF
st.success("تم تحضير التقرير بنجاح! اضغط هنا للتحميل")
# عرض ملخص شامل
st.markdown("""
<div class="metric-card">
<h3>📊 ملخص التحليل الشامل</h3>
""", unsafe_allow_html=True)
summary_cols = st.columns(3)
with summary_cols[0]:
st.markdown("""
#### 🚀 الأداء العام
""")
st.progress(performance_data.get('تقييم الأداء', 0) / 100)
with summary_cols[1]:
st.markdown("""
#### 🎯 تقييم SEO
""")
st.progress(seo_data.get('تقييم SEO الإجمالي', 0) / 100)
with summary_cols[2]:
st.markdown("""
#### 🔒 مستوى الأمان
""")
st.progress(security_data.get('تقييم الحماية', 0) / 100)
# توصيات التحسين
st.markdown("""
### 📈 توصيات التحسين
""")
recommendations = st.expander("عرض التوصيات", expanded=True)
with recommendations:
rec_cols = st.columns(3)
with rec_cols[0]:
st.markdown("#### 🚀 تحسين الأداء")
for rec in performance_data.get('توصيات تحسين الأداء', []):
st.markdown(f"- {rec}")
with rec_cols[1]:
st.markdown("#### 🎯 تحسين SEO")
for rec in seo_data.get('توصيات', []):
st.markdown(f"- {rec}")
with rec_cols[2]:
st.markdown("#### 🔒 تحسين الأمان")
for rec in security_data.get('توصيات الأمان', []):
st.markdown(f"- {rec}")
with col2:
st.subheader("📊 آخر التحليلات")
# إضافة قائمة بآخر المواقع التي تم تحليلها
st.markdown("""
<div class="metric-card">
<h4>آخر 5 مواقع تم تحليلها</h4>
</div>
""", unsafe_allow_html=True)
# يمكن إضافة قاعدة بيانات لتخزين التحليلات السابقة
recent_analyses = [
{"url": "example1.com", "date": "2024-03-15", "score": 85},
{"url": "example2.com", "date": "2024-03-14", "score": 92},
{"url": "example3.com", "date": "2024-03-13", "score": 78}
]
for analysis in recent_analyses:
st.markdown(f"""
<div style='padding: 10px; margin: 5px; background-color: white; border-radius: 5px;'>
🌐 {analysis['url']}<br>
📅 {analysis['date']}<br>
⭐ {analysis['score']}/100
</div>
""", unsafe_allow_html=True)
elif selected == "التقارير السابقة":
st.subheader("📊 التقارير السابقة")
# يمكن إضافة كود لعرض التقارير السابقة
elif selected == "الإحصائيات":
st.subheader("📈 إحصائيات التحليل")
# يمكن إضافة كود لعرض الإحصائيات
elif selected == "الإعدادات":
st.subheader("⚙️ إعدادات التحليل")
# يمكن إضافة كود للإعدادات
if __name__ == "__main__":
main() |