# SEO 检测指南
## 一、本地快速检测
### 1. 只测爬虫识别逻辑(不启动服务)
```bash
cd server
node test-crawler-detection.js
```
会跑多组 User-Agent,看是否把百度/Google 等识别为爬虫、普通浏览器识别为非爬虫。
### 2. 端到端检测(需先启动服务)
**步骤 1:启动 SEO 服务器**
```bash
cd server
npm install
npm run start
```
**步骤 2:另开一个终端,运行检测**
```bash
cd server
npm run test
```
或指定地址:
```bash
# Windows PowerShell
$env:SEO_TEST_URL="http://localhost:3000"; node test-seo.js
# 若部署在线上,可测线上
$env:SEO_TEST_URL="https://www.xingfucha.cn"; node test-seo.js
```
脚本会:
- 用 **百度爬虫 UA** 请求首页、代理页、帮助中心、个人查询等
- 检查响应里是否有:`
`、``、``、``
- 用 **普通浏览器 UA** 再请求一遍,确认仍是 200(SPA 正常)
全部通过即说明:爬虫拿到的是 SEO 模板,普通用户拿到的是 SPA。
---
## 二、用 curl 手动检测
在服务器已启动的前提下,在终端执行:
### 爬虫应拿到“带 TDK 的 HTML”
```bash
# 模拟百度爬虫请求首页
curl -s -A "Baiduspider/2.0" http://localhost:3000/ | findstr /i "title description keywords canonical"
```
应能看到包含「天远数据」的 title,以及 description、keywords、canonical 等标签。
**Windows 下中文乱码说明**:服务器返回的是 UTF-8,CMD 默认是 GBK,直接 `curl … | findstr` 会看到乱码(如 `澶╄繙鏁版嵁`)或出现 “FINDSTR: 写入错误”。可任选一种方式解决:
```cmd
:: 方式 1:先切到 UTF-8 再执行(CMD)
chcp 65001
curl -s -A "Baiduspider/2.0" https://www.tianyuandb.com/ | findstr /i "title description"
```
```powershell
# 方式 2:PowerShell 下指定输出编码
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
curl -s -A "Baiduspider/2.0" https://www.tianyuandb.com/ | Select-String -Pattern "title|description"
```
```cmd
:: 方式 3:保存到文件后用编辑器打开(任意编码都行)
curl -s -A "Baiduspider/2.0" https://www.tianyuandb.com/ -o seo-test.html
:: 用记事本/VSCode 打开 seo-test.html,选 UTF-8 即可看到正确中文
```
```bash
# 看完整 HTML 前几行(含 )
curl -s -A "Baiduspider/2.0" http://localhost:3000/ | more
```
### 普通用户应拿到 SPA(一般是带 script 的 index.html)
```bash
# 不带爬虫 UA,相当于普通浏览器
curl -s http://localhost:3000/ | findstr /i "script root app"
```
通常会有 `id="app"` 或大量 `