#!/usr/bin/env python3 """网站快检(免费单文件脚本):3 项致命检查 + 下一步建议。 用法(大多数电脑自带 python): python quickcheck.py https://你的域名/ 它只做三件事,但这三件是 80% "网站没流量" 的原因: 1. 可访问(HTTP 状态、是否 5xx/超时) 2. 是否 noindex(整站进不了搜索) 3. canonical 是否指向自己(权重分散) 不联网上传任何数据,不发请求到我们服务器,纯本地运行。 完整 12 项报告(含每条可粘贴修法):https://www.mengstone.com/audit/ """ import re import ssl import sys import time import urllib.error import urllib.request UA = {"User-Agent": "Mozilla/5.0 (compatible; QuickCheck/1.0)"} def fetch(url): ctx = ssl.create_default_context() t0 = time.time() try: with urllib.request.urlopen(urllib.request.Request(url, headers=UA), timeout=20, context=ctx) as r: return r.status, r.read(1_500_000).decode("utf-8", errors="replace"), time.time() - t0 except urllib.error.HTTPError as e: return e.code, "", time.time() - t0 except Exception as e: return 0, f"__ERR__{e}", time.time() - t0 def main(): if len(sys.argv) < 2: print(__doc__) return 2 share_mode = "--share" in sys.argv args = [x for x in sys.argv[1:] if not x.startswith("--")] if not args: print(__doc__) return 2 url = args[0].strip() if not url.startswith("http"): url = "https://" + url print(f"体检对象:{url}\n" + "-" * 52) status, html, elapsed = fetch(url) score = 0 max_score = 100 issues = [] # 1 可访问 if status == 200: print(f"[PASS] 可访问 HTTP 200 · {elapsed*1000:.0f}ms") score += 40 else: print(f"[FAIL] 可访问 HTTP {status or '连接失败'}") issues.append(("可访问", "返回非 200:先修服务器/路由/DNS,其他检查都没意义")) print("\n结论:站点打不开,先解决可用性。") return 1 # 2 noindex robots = "".join(re.findall(r']+name=["\']robots["\'][^>]*>', html, re.I)) if "noindex" in robots.lower(): print(f"[FAIL] 是否被索引 noindex(这会让整站进不了搜索)") issues.append(("noindex", '删掉 ,并把该页从 sitemap 保留')) else: print("[PASS] 是否被索引 未发现 noindex") score += 30 # 3 canonical canon = (re.findall(r']+rel=["\']canonical["\'][^>]+href=["\'](.*?)["\']', html, re.I) or [""])[0] if canon and canon.rstrip("/") == url.rstrip("/"): print(f"[PASS] canonical 自指") score += 30 elif canon: print(f"[FAIL] canonical 指向 {canon[:60]}") issues.append(("canonical", f'改成自指:')) else: print("[FAIL] canonical 缺失") issues.append(("canonical", f'在
加:')) print("-" * 52) print(f"快检得分:{score}/{max_score}") if issues: print("\n需要修:") for i, (name, fix) in enumerate(issues, 1): print(f"{i}. {name}") print(f" 修法:{fix}") else: print("三项全过。剩下的 9 项(标题/描述/H1/移动端/alt/结构化/体积/速度/sitemap)需要完整报告。") if share_mode: emoji = "✅" if not issues else "⚠️" print("\n—— 可直接发的分享文案 ——") print(f"{emoji} 用 10 秒给自己网站做了个快检:{score}/100") if issues: print("问题:" + "、".join(n for n, _ in issues)) import urllib.parse as _up _names = ",".join(_up.quote(n) for n, _ in issues) if issues else "" _host = _up.quote(url.split("//")[-1].split("/")[0]) print(f"结果页(可分享):https://www.mengstone.com/audit/c/?s={score}&i={_names}&u={_host}") print("脚本在这(本地跑,不上传数据):https://www.mengstone.com/tools/quickcheck.py") print("—— 复制到这里 ——") print("\n完整 12 项报告 + 每条可粘贴修法:https://www.mengstone.com/audit/ (¥19 快检 / ¥99 完整)") return 0 if __name__ == "__main__": raise SystemExit(main())