from flask import Flask, render_template_string, request
import requests
from bs4 import BeautifulSoup
app = Flask(__name__)
HTML_TEMPLATE = """
🔐 Privacy Score Analyzer
🔐 Privacy Score Analyzer
{% if score is not none %}
🔎 Privacy Score: {{ score }}/100
{% if issues %}
⚠️ Issues Found:
{% for issue in issues %}
- {{ issue }}
{% endfor %}
{% else %}
✅ Excellent! No major privacy issues found.
{% endif %}
{% endif %}
{% if error %}
Error: {{ error }}
{% endif %}
"""
@app.route('/', methods=['GET', 'POST'])
def analyze():
score = None
issues = []
error = None
if request.method == 'POST':
url_input = request.form.get('url', '').strip()
if not url_input:
error = "Please enter a valid URL."
else:
try:
# Add http:// if missing
if not url_input.startswith("http"):
url_input = "http://" + url_input
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
}
response = requests.get(url_input, headers=headers, timeout=8)
html = response.text
soup = BeautifulSoup(html, "html.parser")
score = 100
final_url = response.url
# Check HTTPS
if not final_url.startswith("https"):
score -= 20
issues.append("❌ Website does not use HTTPS.")
# Check trackers
tracker_keywords = ["google-analytics", "doubleclick", "facebook.net"]
trackers_found = []
for script in soup.find_all("script"):
for keyword in tracker_keywords:
if keyword in str(script).lower():
trackers_found.append(keyword)
if trackers_found:
score -= 20
issues.append(f"❌ Trackers found: {', '.join(set(trackers_found))}")
# Check Content-Security-Policy
meta_csp = soup.find("meta", attrs={"http-equiv": "Content-Security-Policy"})
if not meta_csp:
score -= 10
issues.append("❌ Missing Content-Security-Policy tag.")
except requests.exceptions.RequestException as e:
error = f"Network error: {e}"
except Exception as e:
error = f"Unexpected error: {e}"
return render_template_string(HTML_TEMPLATE, score=score, issues=issues, error=error)
if __name__ == '__main__':
app.run(debug=True)