|
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") |
|
|
|
|
|
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)} |
|
|
|
|
|
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_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/) |
|
""") |
|
|
|
|
|
|