Update app.py
Browse files
app.py
CHANGED
|
@@ -1,175 +1,197 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
|
|
|
|
|
|
| 3 |
import whois
|
| 4 |
-
import socket
|
| 5 |
import ssl
|
| 6 |
-
|
|
|
|
| 7 |
from datetime import datetime
|
|
|
|
|
|
|
| 8 |
import matplotlib.pyplot as plt
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import plotly.express as px
|
| 6 |
import whois
|
|
|
|
| 7 |
import ssl
|
| 8 |
+
import socket
|
| 9 |
+
import urllib3
|
| 10 |
from datetime import datetime
|
| 11 |
+
import numpy as np
|
| 12 |
+
from urllib.parse import urlparse
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
+
import seaborn as sns
|
| 15 |
+
from requests.exceptions import RequestException
|
| 16 |
+
import json
|
| 17 |
+
from transformers import pipeline
|
| 18 |
+
import plotly.graph_objects as go
|
| 19 |
+
|
| 20 |
+
# تهيئة الصفحة
|
| 21 |
+
st.set_page_config(page_title="محلل المواقع الذكي", layout="wide", initial_sidebar_state="expanded")
|
| 22 |
+
|
| 23 |
+
# تصميم CSS
|
| 24 |
+
st.markdown("""
|
| 25 |
+
<style>
|
| 26 |
+
.main {
|
| 27 |
+
background-color: #f5f5f5;
|
| 28 |
+
}
|
| 29 |
+
.stButton>button {
|
| 30 |
+
background-color: #0066cc;
|
| 31 |
+
color: white;
|
| 32 |
+
border-radius: 5px;
|
| 33 |
+
padding: 10px 20px;
|
| 34 |
+
}
|
| 35 |
+
.metric-card {
|
| 36 |
+
background-color: white;
|
| 37 |
+
padding: 20px;
|
| 38 |
+
border-radius: 10px;
|
| 39 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 40 |
+
}
|
| 41 |
+
</style>
|
| 42 |
+
""", unsafe_allow_html=True)
|
| 43 |
+
|
| 44 |
+
# العنوان الرئيسي
|
| 45 |
+
st.title("🌐 محلل المواقع والسيو الذكي")
|
| 46 |
+
st.markdown("---")
|
| 47 |
+
|
| 48 |
+
# إدخال رابط الموقع
|
| 49 |
+
url = st.text_input("أدخل رابط الموقع للتحليل", "https://example.com")
|
| 50 |
+
|
| 51 |
+
if st.button("تحليل الموقع"):
|
| 52 |
+
try:
|
| 53 |
+
# التحقق من صحة الرابط
|
| 54 |
+
if not url.startswith(('http://', 'https://')):
|
| 55 |
+
url = 'https://' + url
|
| 56 |
+
|
| 57 |
+
# تحليل الأمان
|
| 58 |
+
def analyze_security(url):
|
| 59 |
+
try:
|
| 60 |
+
domain = urlparse(url).netloc
|
| 61 |
+
context = ssl.create_default_context()
|
| 62 |
+
with socket.create_connection((domain, 443)) as sock:
|
| 63 |
+
with context.wrap_socket(sock, server_hostname=domain) as ssock:
|
| 64 |
+
cert = ssock.getpeercert()
|
| 65 |
+
ssl_version = ssock.version()
|
| 66 |
+
return {
|
| 67 |
+
"ssl_version": ssl_version,
|
| 68 |
+
"cert_expiry": datetime.strptime(cert['notAfter'], '%b %d %H:%M:%S %Y %Z'),
|
| 69 |
+
"secure": True
|
| 70 |
+
}
|
| 71 |
+
except Exception as e:
|
| 72 |
+
return {"secure": False, "error": str(e)}
|
| 73 |
+
|
| 74 |
+
# تحليل SEO
|
| 75 |
+
def analyze_seo(soup, url):
|
| 76 |
+
seo_data = {
|
| 77 |
+
"title": soup.title.string if soup.title else "لا يوجد عنوان",
|
| 78 |
+
"meta_description": soup.find("meta", {"name": "description"})["content"] if soup.find("meta", {"name": "description"}) else "لا يوجد وصف",
|
| 79 |
+
"h1_count": len(soup.find_all("h1")),
|
| 80 |
+
"h2_count": len(soup.find_all("h2")),
|
| 81 |
+
"images_without_alt": len([img for img in soup.find_all("img") if not img.get("alt")]),
|
| 82 |
+
"links_count": len(soup.find_all("a")),
|
| 83 |
+
}
|
| 84 |
+
return seo_data
|
| 85 |
+
|
| 86 |
+
# جلب البيانات وتحليلها
|
| 87 |
+
response = requests.get(url, verify=False)
|
| 88 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 89 |
+
|
| 90 |
+
# تحليل الأمان
|
| 91 |
+
security_info = analyze_security(url)
|
| 92 |
+
|
| 93 |
+
# تحليل SEO
|
| 94 |
+
seo_info = analyze_seo(soup, url)
|
| 95 |
+
|
| 96 |
+
# عرض النتائج في أقسام
|
| 97 |
+
col1, col2, col3 = st.columns(3)
|
| 98 |
+
|
| 99 |
+
with col1:
|
| 100 |
+
st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
|
| 101 |
+
st.subheader("🔒 تحليل الأمان")
|
| 102 |
+
st.write(f"حالة SSL: {'آمن' if security_info['secure'] else 'غير آمن'}")
|
| 103 |
+
if security_info['secure']:
|
| 104 |
+
st.write(f"نسخة SSL: {security_info['ssl_version']}")
|
| 105 |
+
st.write(f"تاريخ انتهاء الشهادة: {security_info['cert_expiry'].strftime('%Y-%m-%d')}")
|
| 106 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 107 |
+
|
| 108 |
+
with col2:
|
| 109 |
+
st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
|
| 110 |
+
st.subheader("🎯 تحليل SEO")
|
| 111 |
+
st.write(f"العنوان: {seo_info['title']}")
|
| 112 |
+
st.write(f"عدد العناوين H1: {seo_info['h1_count']}")
|
| 113 |
+
st.write(f"عدد العناوين H2: {seo_info['h2_count']}")
|
| 114 |
+
st.write(f"عدد الروابط: {seo_info['links_count']}")
|
| 115 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 116 |
+
|
| 117 |
+
with col3:
|
| 118 |
+
st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
|
| 119 |
+
st.subheader("📊 التقييم العام")
|
| 120 |
+
# حساب التقييم العام
|
| 121 |
+
security_score = 100 if security_info['secure'] else 0
|
| 122 |
+
seo_score = min(100, (seo_info['h1_count'] * 10 +
|
| 123 |
+
seo_info['h2_count'] * 5 +
|
| 124 |
+
(seo_info['links_count'] > 0) * 20 +
|
| 125 |
+
(len(seo_info['title']) > 0) * 20))
|
| 126 |
+
total_score = (security_score + seo_score) / 2
|
| 127 |
+
|
| 128 |
+
# رسم مقياس دائري للتقييم
|
| 129 |
+
fig = go.Figure(go.Indicator(
|
| 130 |
+
mode = "gauge+number",
|
| 131 |
+
value = total_score,
|
| 132 |
+
domain = {'x': [0, 1], 'y': [0, 1]},
|
| 133 |
+
title = {'text': "التقييم العام"},
|
| 134 |
+
gauge = {
|
| 135 |
+
'axis': {'range': [0, 100]},
|
| 136 |
+
'bar': {'color': "darkblue"},
|
| 137 |
+
'steps': [
|
| 138 |
+
{'range': [0, 50], 'color': "lightgray"},
|
| 139 |
+
{'range': [50, 75], 'color': "gray"},
|
| 140 |
+
{'range': [75, 100], 'color': "darkgray"}
|
| 141 |
+
],
|
| 142 |
+
}))
|
| 143 |
+
st.plotly_chart(fig)
|
| 144 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 145 |
+
|
| 146 |
+
# التوصيات والتحسينات
|
| 147 |
+
st.markdown("### 📝 التوصيات والتحسينات")
|
| 148 |
+
recommendations = []
|
| 149 |
+
|
| 150 |
+
if not security_info['secure']:
|
| 151 |
+
recommendations.append("🔒 يجب تفعيل شهادة SSL للموقع")
|
| 152 |
+
if seo_info['h1_count'] == 0:
|
| 153 |
+
recommendations.append("📌 يجب إضافة عنوان H1 للصفحة الرئيسية")
|
| 154 |
+
if len(seo_info['title']) < 30:
|
| 155 |
+
recommendations.append("📑 يجب تحسين عنوان الصفحة ليكون أكثر تفصيلاً")
|
| 156 |
+
if seo_info['images_without_alt'] > 0:
|
| 157 |
+
recommendations.append(f"🖼️ يجب إضافة نص بديل لـ {seo_info['images_without_alt']} صورة")
|
| 158 |
+
|
| 159 |
+
for rec in recommendations:
|
| 160 |
+
st.write(rec)
|
| 161 |
+
|
| 162 |
+
# رسم بياني للمقارنة
|
| 163 |
+
st.markdown("### 📊 تحليل مقارن")
|
| 164 |
+
comparison_data = {
|
| 165 |
+
'المعيار': ['الأمان', 'SEO', 'التقييم العام'],
|
| 166 |
+
'النتيجة': [security_score, seo_score, total_score]
|
| 167 |
+
}
|
| 168 |
+
df = pd.DataFrame(comparison_data)
|
| 169 |
+
fig = px.bar(df, x='المعيار', y='النتيجة',
|
| 170 |
+
title='مقارنة نتائج التحليل',
|
| 171 |
+
color='النتيجة',
|
| 172 |
+
color_continuous_scale='Viridis')
|
| 173 |
+
st.plotly_chart(fig)
|
| 174 |
+
|
| 175 |
+
except Exception as e:
|
| 176 |
+
st.error(f"حدث خطأ أثناء تحليل الموقع: {str(e)}")
|
| 177 |
+
|
| 178 |
+
# إضافة معلومات إضافية في الشريط الجانبي
|
| 179 |
+
with st.sidebar:
|
| 180 |
+
st.header("ℹ️ معلومات إضافية")
|
| 181 |
+
st.write("""
|
| 182 |
+
هذا التطبيق يقوم بتحليل:
|
| 183 |
+
- 🔒 أمان الموقع وشهادات SSL
|
| 184 |
+
- 📊 تحليل SEO
|
| 185 |
+
- 📈 تقييم أداء الموقع
|
| 186 |
+
- 🎯 تقديم توصيات للتحسين
|
| 187 |
+
""")
|
| 188 |
+
|
| 189 |
+
st.markdown("---")
|
| 190 |
+
st.markdown("### 📚 مصادر مفيدة")
|
| 191 |
+
st.markdown("""
|
| 192 |
+
- [دليل SEO](https://developers.google.com/search/docs)
|
| 193 |
+
- [أفضل ممارسات الأمان](https://www.cloudflare.com/learning/security/what-is-web-security/)
|
| 194 |
+
""")
|
| 195 |
+
|
| 196 |
+
# Created/Modified files during execution:
|
| 197 |
+
# No files are created or modified during execution as this is a Streamlit web application
|