File size: 8,080 Bytes
a3acd70
b43f4c5
d373a49
 
 
45a9528
0a58343
d373a49
 
0a58343
d373a49
 
9875a3c
d373a49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
from bs4 import BeautifulSoup
import pandas as pd
import plotly.express as px
import whois
import ssl
import socket
import urllib3
from datetime import datetime
import numpy as np
from urllib.parse import urlparse
import matplotlib.pyplot as plt
import seaborn as sns
from requests.exceptions import RequestException
import json
from transformers import pipeline
import plotly.graph_objects as go

# تهيئة الصفحة
st.set_page_config(page_title="محلل المواقع الذكي", layout="wide", initial_sidebar_state="expanded")

# تصميم CSS
st.markdown("""
<style>
    .main {
        background-color: #f5f5f5;
    }
    .stButton>button {
        background-color: #0066cc;
        color: white;
        border-radius: 5px;
        padding: 10px 20px;
    }
    .metric-card {
        background-color: white;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
</style>
""", unsafe_allow_html=True)

# العنوان الرئيسي
st.title("🌐 محلل المواقع والسيو الذكي")
st.markdown("---")

# إدخال رابط الموقع
url = st.text_input("أدخل رابط الموقع للتحليل", "https://example.com")

if st.button("تحليل الموقع"):
    try:
        # التحقق من صحة الرابط
        if not url.startswith(('http://', 'https://')):
            url = 'https://' + url

        # تحليل الأمان
        def analyze_security(url):
            try:
                domain = urlparse(url).netloc
                context = ssl.create_default_context()
                with socket.create_connection((domain, 443)) as sock:
                    with context.wrap_socket(sock, server_hostname=domain) as ssock:
                        cert = ssock.getpeercert()
                        ssl_version = ssock.version()
                        return {
                            "ssl_version": ssl_version,
                            "cert_expiry": datetime.strptime(cert['notAfter'], '%b %d %H:%M:%S %Y %Z'),
                            "secure": True
                        }
            except Exception as e:
                return {"secure": False, "error": str(e)}

        # تحليل SEO
        def analyze_seo(soup, url):
            seo_data = {
                "title": soup.title.string if soup.title else "لا يوجد عنوان",
                "meta_description": soup.find("meta", {"name": "description"})["content"] if soup.find("meta", {"name": "description"}) else "لا يوجد وصف",
                "h1_count": len(soup.find_all("h1")),
                "h2_count": len(soup.find_all("h2")),
                "images_without_alt": len([img for img in soup.find_all("img") if not img.get("alt")]),
                "links_count": len(soup.find_all("a")),
            }
            return seo_data

        # جلب البيانات وتحليلها
        response = requests.get(url, verify=False)
        soup = BeautifulSoup(response.text, 'html.parser')
        
        # تحليل الأمان
        security_info = analyze_security(url)
        
        # تحليل SEO
        seo_info = analyze_seo(soup, url)

        # عرض النتائج في أقسام
        col1, col2, col3 = st.columns(3)
        
        with col1:
            st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
            st.subheader("🔒 تحليل الأمان")
            st.write(f"حالة SSL: {'آمن' if security_info['secure'] else 'غير آمن'}")
            if security_info['secure']:
                st.write(f"نسخة SSL: {security_info['ssl_version']}")
                st.write(f"تاريخ انتهاء الشهادة: {security_info['cert_expiry'].strftime('%Y-%m-%d')}")
            st.markdown("</div>", unsafe_allow_html=True)

        with col2:
            st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
            st.subheader("🎯 تحليل SEO")
            st.write(f"العنوان: {seo_info['title']}")
            st.write(f"عدد العناوين H1: {seo_info['h1_count']}")
            st.write(f"عدد العناوين H2: {seo_info['h2_count']}")
            st.write(f"عدد الروابط: {seo_info['links_count']}")
            st.markdown("</div>", unsafe_allow_html=True)

        with col3:
            st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
            st.subheader("📊 التقييم العام")
            # حساب التقييم العام
            security_score = 100 if security_info['secure'] else 0
            seo_score = min(100, (seo_info['h1_count'] * 10 + 
                                seo_info['h2_count'] * 5 + 
                                (seo_info['links_count'] > 0) * 20 +
                                (len(seo_info['title']) > 0) * 20))
            total_score = (security_score + seo_score) / 2
            
            # رسم مقياس دائري للتقييم
            fig = go.Figure(go.Indicator(
                mode = "gauge+number",
                value = total_score,
                domain = {'x': [0, 1], 'y': [0, 1]},
                title = {'text': "التقييم العام"},
                gauge = {
                    'axis': {'range': [0, 100]},
                    'bar': {'color': "darkblue"},
                    'steps': [
                        {'range': [0, 50], 'color': "lightgray"},
                        {'range': [50, 75], 'color': "gray"},
                        {'range': [75, 100], 'color': "darkgray"}
                    ],
                }))
            st.plotly_chart(fig)
            st.markdown("</div>", unsafe_allow_html=True)

        # التوصيات والتحسينات
        st.markdown("### 📝 التوصيات والتحسينات")
        recommendations = []
        
        if not security_info['secure']:
            recommendations.append("🔒 يجب تفعيل شهادة SSL للموقع")
        if seo_info['h1_count'] == 0:
            recommendations.append("📌 يجب إضافة عنوان H1 للصفحة الرئيسية")
        if len(seo_info['title']) < 30:
            recommendations.append("📑 يجب تحسين عنوان الصفحة ليكون أكثر تفصيلاً")
        if seo_info['images_without_alt'] > 0:
            recommendations.append(f"🖼️ يجب إضافة نص بديل لـ {seo_info['images_without_alt']} صورة")

        for rec in recommendations:
            st.write(rec)

        # رسم بياني للمقارنة
        st.markdown("### 📊 تحليل مقارن")
        comparison_data = {
            'المعيار': ['الأمان', 'SEO', 'التقييم العام'],
            'النتيجة': [security_score, seo_score, total_score]
        }
        df = pd.DataFrame(comparison_data)
        fig = px.bar(df, x='المعيار', y='النتيجة',
                    title='مقارنة نتائج التحليل',
                    color='النتيجة',
                    color_continuous_scale='Viridis')
        st.plotly_chart(fig)

    except Exception as e:
        st.error(f"حدث خطأ أثناء تحليل الموقع: {str(e)}")

# إضافة معلومات إضافية في الشريط الجانبي
with st.sidebar:
    st.header("ℹ️ معلومات إضافية")
    st.write("""
    هذا التطبيق يقوم بتحليل:
    - 🔒 أمان الموقع وشهادات SSL
    - 📊 تحليل SEO
    - 📈 تقييم أداء الموقع
    - 🎯 تقديم توصيات للتحسين
    """)
    
    st.markdown("---")
    st.markdown("### 📚 مصادر مفيدة")
    st.markdown("""
    - [دليل SEO](https://developers.google.com/search/docs)
    - [أفضل ممارسات الأمان](https://www.cloudflare.com/learning/security/what-is-web-security/)
    """)

# Created/Modified files during execution:
# No files are created or modified during execution as this is a Streamlit web application