File size: 10,989 Bytes
a3acd70
 
b43f4c5
a3acd70
 
 
 
 
 
 
b43f4c5
a3acd70
 
 
 
 
 
 
 
 
 
0799651
 
48814e4
 
 
 
 
 
 
b895560
b43f4c5
1148762
0799651
 
 
 
 
 
b43f4c5
1148762
a3acd70
 
48814e4
 
 
 
 
 
a3acd70
0799651
 
 
 
 
 
 
 
48814e4
 
 
a3acd70
48814e4
0799651
 
48814e4
 
 
 
 
 
 
 
 
 
 
 
0799651
 
a3acd70
0799651
a3acd70
0799651
48814e4
a3acd70
48814e4
0799651
48814e4
 
 
a3acd70
48814e4
a3acd70
0799651
48814e4
a3acd70
0799651
 
 
48814e4
0799651
 
 
 
 
48814e4
 
 
 
 
 
 
 
0799651
 
 
a3acd70
 
48814e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3acd70
 
 
b43f4c5
48814e4
a3acd70
 
0799651
a3acd70
48814e4
 
a54100a
a997194
a3acd70
 
 
 
 
 
48814e4
 
 
 
0799651
48814e4
 
 
 
 
 
 
 
a3acd70
0799651
 
a3acd70
0799651
 
a54100a
 
 
a3acd70
a54100a
 
 
48814e4
a54100a
 
 
a3acd70
0a285a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a54100a
 
 
 
 
 
 
 
0a285a8
 
1148762
0a285a8
 
 
 
48814e4
0a285a8
 
 
 
a3acd70
0a285a8
 
 
 
 
 
48814e4
0a285a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48814e4
0a285a8
 
 
 
 
 
48814e4
0a285a8
 
 
 
 
 
a3acd70
0a285a8
 
 
 
 
 
1148762
0a285a8
 
 
 
 
 
 
 
 
 
 
 
1148762
0a285a8
 
 
 
 
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
import streamlit as st
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 PIL import Image
import io
import time
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import timedelta
import tldextract
from concurrent.futures import ThreadPoolExecutor
import re
from collections import Counter
from wordcloud import WordCloud
import advertools as adv
from collections import Counter

# Page configuration
st.set_page_config(
    layout="wide",
    page_title="محلل المواقع المتقدم | Website Analyzer Pro",
    page_icon="🔍",
    initial_sidebar_state="expanded"
)

# Custom CSS
st.markdown("""
<style>
    @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');
    
    * {
        font-family: 'Tajawal', sans-serif;
    }
    
    .main {
        background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        padding: 20px;
    }
    
    .metric-card {
        background: white;
        border-radius: 15px;
        padding: 20px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        transition: all 0.3s ease;
        margin-bottom: 20px;
    }
    
    .metric-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    }
    
    .metric-value {
        font-size: 2em;
        font-weight: bold;
        color: #2196F3;
    }
    
    .metric-label {
        color: #666;
        font-size: 1.1em;
    }
    
    .stButton>button {
        background: linear-gradient(45deg, #2196F3, #21CBF3);
        color: white;
        border-radius: 25px;
        padding: 15px 30px;
        border: none;
        box-shadow: 0 4px 15px rgba(33,150,243,0.3);
        transition: all 0.3s ease;
        font-size: 1.1em;
        font-weight: 500;
        width: 100%;
    }
    
    .stButton>button:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(33,150,243,0.4);
    }
    
    h1, h2, h3 {
        color: #1E3D59;
        font-weight: 700;
    }
    
    .stTextInput>div>div>input {
        border-radius: 10px;
        border: 2px solid #E0E0E0;
        padding: 12px;
        font-size: 1.1em;
        transition: all 0.3s ease;
    }
    
    .stTextInput>div>div>input:focus {
        border-color: #2196F3;
        box-shadow: 0 0 0 2px rgba(33,150,243,0.2);
    }
    
    .streamlit-expanderHeader {
        background-color: white;
        border-radius: 10px;
        padding: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    .stProgress > div > div > div {
        background-color: #2196F3;
    }
    
    .tab-content {
        padding: 20px;
        background: white;
        border-radius: 15px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    }
    
    .insight-card {
        background: #f8f9fa;
        border-right: 4px solid #2196F3;
        padding: 15px;
        margin: 10px 0;
        border-radius: 8px;
    }
    
    .chart-container {
        background: white;
        padding: 20px;
        border-radius: 15px;
        box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        margin: 20px 0;
    }
</style>
""", unsafe_allow_html=True)

class AdvancedWebsiteAnalyzer:
    def __init__(self):
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
        }
        self.history = self.load_history()
    
    # [Previous methods remain the same until analyze_seo]

    async def analyze_seo(self, url):
        try:
            async with httpx.AsyncClient() as client:
                response = await client.get(url)
                soup = BeautifulSoup(response.text, 'html.parser')
                
                content_analysis = self._analyze_content(soup)
                links_analysis = self._analyze_links(soup)
                keywords_analysis = self._extract_keywords(soup)
                
                seo_analysis = {
                    "تحليل العنوان": self._analyze_title(soup),
                    "تحليل الوصف": self._analyze_description(soup),
                    "تحليل الكلمات المفتاحية": keywords_analysis,
                    "تحليل العناوين": self._analyze_headings(soup),
                    "تحليل الروابط": links_analysis,
                    "تحليل المحتوى": content_analysis,
                    "تقييم SEO": self._calculate_seo_score(soup),
                    "توصيات تحسين SEO": self._get_seo_recommendations(soup)
                }
                
                return seo_analysis
        except Exception as e:
            return {"error": f"خطأ في تحليل SEO: {str(e)}"}

    def _extract_keywords(self, soup):
        # Add implementation for keyword extraction
        pass

    def _calculate_seo_score(self, soup):
        # Add implementation for SEO scoring
        pass

    def _get_seo_recommendations(self, soup):
        # Add implementation for SEO recommendations
        pass

    def _analyze_content(self, soup):
        """
        Analyzes webpage content for SEO factors
        """
        try:
            text_content = ' '.join([p.text.strip() for p in soup.find_all(['p', 'div', 'article', 'section'])])
            headings = {f'h{i}': len(soup.find_all(f'h{i}')) for i in range(1, 7)}
            words = text_content.split()
            word_count = len(words)
            readability_score = self._calculate_readability(text_content)
            keyword_density = self._calculate_keyword_density(text_content)
            
            images = soup.find_all('img')
            images_with_alt = len([img for img in images if img.get('alt')])
            
            quality_score = self._calculate_content_quality_score(
                word_count,
                readability_score,
                images_with_alt,
                len(images),
                headings
            )
            
            return {
                "إحصائيات المحتوى": {
                    "عدد الكلمات": word_count,
                    "مستوى القراءة": readability_score,
                    "نسبة الصور مع نص بديل": f"{(images_with_alt/len(images)*100 if images else 0):.1f}%",
                    "توزيع العناوين": headings,
                },
                "تحليل الكلمات المفتاحية": {
                    "كثافة الكلمات الرئيسية": keyword_density,
                    "الكلمات الأكثر تكراراً": self._get_top_words(text_content, 5)
                },
                "تقييم جودة المحتوى": {
                    "الدرجة": quality_score,
                    "التقييم": self._get_content_rating(quality_score),
                    "التوصيات": self._get_content_recommendations(
                        word_count,
                        readability_score,
                        images_with_alt,
                        len(images),
                        headings
                    )
                }
            }
        except Exception as e:
            return {"error": f"خطأ في تحليل المحتوى: {str(e)}"}

    def _calculate_readability(self, text):
        # Add implementation for readability calculation
        pass

    def _calculate_keyword_density(self, text):
        # Add implementation for keyword density calculation
        pass

    def _calculate_content_quality_score(self, word_count, readability, alt_images, total_images, headings):
        score = 100
        
        if word_count < 300:
            score -= 20
        elif word_count < 600:
            score -= 10
        
        if readability < 40:
            score -= 15
        elif readability < 60:
            score -= 10
        
        if total_images > 0:
            alt_ratio = alt_images / total_images
            if alt_ratio < 0.5:
                score -= 15
            elif alt_ratio < 0.8:
                score -= 10
        
        if headings.get('h1', 0) == 0:
            score -= 10
        if headings.get('h1', 0) > 1:
            score -= 5
        if headings.get('h2', 0) == 0:
            score -= 5
            
        return max(0, score)

    def _get_content_rating(self, score):
        if score >= 90:
            return "ممتاز"
        elif score >= 80:
            return "جيد جداً"
        elif score >= 70:
            return "جيد"
        elif score >= 60:
            return "مقبول"
        else:
            return "يحتاج تحسين"

    def _get_content_recommendations(self, word_count, readability, alt_images, total_images, headings):
        recommendations = []
        
        if word_count < 300:
            recommendations.append({
                "المشكلة": "محتوى قصير جداً",
                "الحل": "زيادة المحتوى إلى 300 كلمة على الأقل",
                "الأولوية": "عالية"
            })
        
        if readability < 60:
            recommendations.append({
                "المشكلة": "صعوبة قراءة المحتوى",
                "الحل": "تبسيط الجمل واستخدام لغة أسهل",
                "الأولوية": "متوسطة"
            })
        
        if total_images > 0 and (alt_images / total_images) < 0.8:
            recommendations.append({
                "المشكلة": "نقص في النصوص البديلة للصور",
                "الحل": "إضافة نص بديل وصفي لجميع الصور",
                "الأولوية": "عالية"
            })
        
        if headings.get('h1', 0) != 1:
            recommendations.append({
                "المشكلة": "عدد غير مناسب من عناوين H1",
                "الحل": "استخدام عنوان H1 واحد فقط للصفحة",
                "الأولوية": "عالية"
            })
        
        return recommendations if recommendations else [{
            "المشكلة": "لا توجد مشاكل واضحة",
            "الحل": "الاستمرار في تحديث المحتوى بشكل دوري",
            "الأولوية": "منخفضة"
        }]

    def _get_top_words(self, text, count=5):
        stop_words = set(['و', 'في', 'من', 'على', 'the', 'and', 'in', 'of', 'to'])
        words = text.lower().split()
        word_freq = Counter(word for word in words if word not in stop_words and len(word) > 2)
        return {word: count for word, count in word_freq.most_common(count)}