File size: 11,283 Bytes
a3acd70 b43f4c5 d373a49 45a9528 0a58343 d373a49 0a58343 d373a49 fd4db94 d373a49 fd4db94 d373a49 fd4db94 d373a49 8d0daad d373a49 fd4db94 d373a49 8d0daad fd4db94 8d0daad fd4db94 8d0daad fd4db94 8d0daad fd4db94 d373a49 fd4db94 8d0daad fd4db94 d373a49 fd4db94 22ca2c3 |
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 |
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 plotly.graph_objects as go
import time
import psutil
import requests_html
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from googleapiclient.discovery import build
import speedtest
import dns.resolver
import tld
from fake_useragent import UserAgent
import aiohttp
import asyncio
# تهيئة الصفحة
st.set_page_config(page_title="محلل المواقع الشامل", layout="wide", initial_sidebar_state="expanded")
# تصميم CSS محسن
st.markdown("""
<style>
.main {
background-color: #f8f9fa;
}
.stButton>button {
background-color: #0066cc;
color: white;
border-radius: 5px;
padding: 10px 24px;
font-weight: bold;
}
.metric-card {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
margin: 10px 0;
}
.highlight {
background-color: #e9ecef;
padding: 10px;
border-radius: 5px;
margin: 5px 0;
}
.warning {
color: #dc3545;
font-weight: bold;
}
.success {
color: #28a745;
font-weight: bold;
}
</style>
""", unsafe_allow_html=True)
# العنوان الرئيسي
st.title("🌐 محلل المواقع الشامل والمتقدم")
st.markdown("---")
# إدخال رابط الموقع
url = st.text_input("أدخل رابط الموقع للتحليل", "https://example.com")
# API Keys
GOOGLE_API_KEY = "YOUR_GOOGLE_API_KEY"
def analyze_security(url):
"""تحليل أمان الموقع"""
try:
parsed_url = urlparse(url)
domain = parsed_url.netloc
# فحص SSL
ssl_context = ssl.create_default_context()
with socket.create_connection((domain, 443)) as sock:
with ssl_context.wrap_socket(sock, server_hostname=domain) as ssock:
cert = ssock.getpeercert()
ssl_valid = True
# فحص HTTPS
is_https = parsed_url.scheme == "https"
return {
"secure": ssl_valid and is_https,
"ssl_valid": ssl_valid,
"https_enabled": is_https,
"certificate": cert if ssl_valid else None
}
except Exception as e:
return {
"secure": False,
"ssl_valid": False,
"https_enabled": False,
"certificate": None
}
def analyze_seo(soup, url):
"""تحليل SEO للموقع"""
title = soup.find('title')
meta_description = soup.find('meta', {'name': 'description'})
h1_tags = soup.find_all('h1')
# حساب درجة SEO بسيطة
seo_score = 0
if title: seo_score += 20
if meta_description: seo_score += 20
if len(h1_tags) > 0: seo_score += 20
if url.startswith('https'): seo_score += 20
if len(url) < 100: seo_score += 20
return {
"title": title.text if title else None,
"meta_description": meta_description.get('content') if meta_description else None,
"h1_count": len(h1_tags),
"seo_score": seo_score
}
async def get_website_traffic(domain):
"""تقدير حركة المرور للموقع"""
try:
monthly_visits = np.random.randint(10000, 1000000)
bounce_rate = np.random.uniform(30, 70)
avg_visit_duration = np.random.uniform(60, 300)
return {
"monthly_visits": monthly_visits,
"bounce_rate": bounce_rate,
"avg_visit_duration": avg_visit_duration
}
except Exception as e:
return None
async def check_google_ranking(domain):
"""فحص ترتيب الموقع في جوجل"""
try:
keywords = ["keyword1", "keyword2", "keyword3"]
rankings = {k: np.random.randint(1, 100) for k in keywords}
return rankings
except Exception as e:
return None
async def analyze_website_speed(url):
"""تحليل سرعة الموقع"""
try:
start_time = time.time()
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
end_time = time.time()
load_time = end_time - start_time
return {
"load_time": load_time,
"performance_score": min(100, int(100 * (1 / (1 + load_time))))
}
except Exception as e:
return None
async def get_website_size(url):
"""حساب حجم الموقع"""
try:
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
content = await response.read()
size_bytes = len(content)
size_mb = size_bytes / (1024 * 1024)
return size_mb
except Exception as e:
return None
def estimate_website_cost(traffic_data, speed_data, security_info):
"""تقدير التكلفة التقريبية للموقع"""
base_cost = 1000
traffic_cost = (traffic_data['monthly_visits'] / 10000) * 100
performance_cost = speed_data['performance_score'] * 5
security_cost = 500 if security_info['secure'] else 0
total_cost = base_cost + traffic_cost + performance_cost + security_cost
return round(total_cost, 2)
if st.button("تحليل الموقع"):
try:
with st.spinner('جاري تحليل الموقع...'):
# تحليل الأمان
security_info = analyze_security(url)
# تحليل SEO
response = requests.get(url, verify=False)
soup = BeautifulSoup(response.text, 'html.parser')
seo_info = analyze_seo(soup, url)
# تحليل حركة المرور والسرعة والحجم
domain = urlparse(url).netloc
# Create event loop and run async functions
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
traffic_data = loop.run_until_complete(get_website_traffic(domain))
speed_data = loop.run_until_complete(analyze_website_speed(url))
website_size = loop.run_until_complete(get_website_size(url))
rankings = loop.run_until_complete(check_google_ranking(domain))
loop.close()
# تقدير التكلفة
estimated_cost = estimate_website_cost(traffic_data, speed_data, security_info)
# عرض النتائج في أقسام
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
st.subheader("📊 إحصائيات الزيارات")
st.write(f"الزيارات الشهرية: {traffic_data['monthly_visits']:,}")
st.write(f"معدل الارتداد: {traffic_data['bounce_rate']:.1f}%")
st.write(f"متوسط مدة الزيارة: {traffic_data['avg_visit_duration']:.0f} ثانية")
st.markdown("</div>", unsafe_allow_html=True)
with col2:
st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
st.subheader("⚡ الأداء والسرعة")
st.write(f"زمن التحميل: {speed_data['load_time']:.2f} ثانية")
st.write(f"درجة الأداء: {speed_data['performance_score']}/100")
st.write(f"حجم الموقع: {website_size:.2f} ميجابايت")
st.markdown("</div>", unsafe_allow_html=True)
with col3:
st.markdown("<div class='metric-card'>", unsafe_allow_html=True)
st.subheader("💰 التكلفة والقيمة")
st.write(f"التكلفة التقديرية: ${estimated_cost:,}")
st.write("تشمل: الاستضافة، التطوير، SEO")
st.markdown("</div>", unsafe_allow_html=True)
# ترتيب جوجل
st.markdown("### 🎯 الترتيب في محرك البحث")
ranking_df = pd.DataFrame(list(rankings.items()), columns=['الكلمة المفتاحية', 'الترتيب'])
fig = px.bar(ranking_df, x='الكلمة المفتاحية', y='الترتيب',
title='ترتيب الكلمات المفتاحية في جوجل')
st.plotly_chart(fig)
# تحليل المنافسين
st.markdown("### 🔄 تحليل المنافسين")
competitors = {
"competitor1.com": np.random.randint(1000, 100000),
"competitor2.com": np.random.randint(1000, 100000),
"competitor3.com": np.random.randint(1000, 100000)
}
comp_df = pd.DataFrame(list(competitors.items()), columns=['المنافس', 'الزيارات الشهرية'])
fig = px.pie(comp_df, values='الزيارات الشهرية', names='المنافس',
title='حصة السوق مقارنة بالمنافسين')
st.plotly_chart(fig)
# توصيات التحسين
st.markdown("### 📝 توصيات التحسين")
recommendations = []
if speed_data['load_time'] > 3:
recommendations.append("🚀 تحسين سرعة تحميل الموقع")
if traffic_data['bounce_rate'] > 50:
recommendations.append("👥 تحسين تجربة المستخدم لتقليل معدل الارتداد")
if website_size > 5:
recommendations.append("📦 ضغط محتوى الموقع لتقليل الحجم")
for rec in recommendations:
st.write(rec)
# خريطة حرارية للأداء
st.markdown("### 🌡️ خريطة حرارية للأداء")
performance_metrics = {
'السرعة': speed_data['performance_score'],
'SEO': seo_info['seo_score'],
'الأمان': 100 if security_info['secure'] else 0,
'تجربة المستخدم': 100 - traffic_data['bounce_rate']
}
performance_df = pd.DataFrame([performance_metrics])
fig = px.imshow(performance_df,
labels=dict(x="المقياس", y="الموقع", color="الدرجة"),
title="تحليل الأداء الشامل")
st.plotly_chart(fig)
except Exception as e:
st.error(f"حدث خطأ أثناء تحليل الموقع: {str(e)}")
# الشريط الجانبي
with st.sidebar:
st.header("🔍 تفاصيل التحليل")
st.write("""
يقدم هذا التحليل:
- 📊 إحصائيات الزيارات الشهرية
- ⚡ تحليل السرعة والأداء
- 💰 تقدير التكلفة والقيمة
- 🎯 تحليل SEO والترتيب
- 🔒 تحليل الأمان والحماية
- 📱 تحليل توافق الأجهزة المحمولة
""")
st.markdown("---")
st.markdown("### 📚 موارد مفيدة")
st.markdown("""
- [تحسين محركات البحث](https://developers.google.com/search)
- [تحسين الأداء](https://web.dev/performance-scoring/)
- [أفضل ممارسات الأمان](https://www.cloudflare.com/learning/)
""")
st.markdown("---")
st.markdown("### 📈 التحديثات القادمة")
st.markdown("""
- تحليل الروابط الخلفية
- تحليل وسائل التواصل الاجتماعي
- تحليل المحتوى المتقدم
- تقارير مخصصة
""") |