File size: 2,099 Bytes
ad06665 | 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 | import sqlite3
import requests
from bs4 import BeautifulSoup
import random
import os
DB_PATH = "data/satellites.db"
OUTPUT_DIR = "data/debug_pages"
def analyze_random_satellites(count=15):
os.makedirs(OUTPUT_DIR, exist_ok=True)
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
# Get all China satellites
satellites = cursor.execute("SELECT satellite_name, url FROM satellites WHERE country_name='China'").fetchall()
conn.close()
if not satellites:
print("No satellites found in DB.")
return
selected = random.sample(satellites, min(count, len(satellites)))
print(f"Analyzing {len(selected)} random satellites...")
for name, url in selected:
print(f"\nFetching: {name} | {url}")
try:
resp = requests.get(url, headers={"User-Agent": "Mozilla/5.0"})
resp.raise_for_status()
soup = BeautifulSoup(resp.text, "lxml")
# 1. Check for specification table (id="satdata")
satdata = soup.find("table", id="satdata")
has_satdata = "✅ Found" if satdata else "❌ Missing"
# 2. Check for description
desc = soup.find("div", id="satdescription")
has_desc = "✅ Found" if desc else "❌ Missing"
# 3. Check for launch list (id="satlist")
satlist = soup.find("table", id="satlist")
has_satlist = "✅ Found" if satlist else "❌ Missing"
print(f" - SatData: {has_satdata}")
print(f" - Desc: {has_desc}")
print(f" - Launch: {has_satlist}")
# Save HTML for deep inspection if needed
safe_name = "".join(c for c in name if c.isalnum() or c in (' ', '-', '_')).strip()
with open(f"{OUTPUT_DIR}/{safe_name}.html", "w", encoding="utf-8") as f:
f.write(resp.text)
except Exception as e:
print(f" ❌ Error: {e}")
if __name__ == "__main__":
analyze_random_satellites()
|