技术 SEO
High Contrast
Dark Mode
Light Mode
Sepia
Forest
2 min read432 words

技术 SEO

技术 SEO 是基础——如果搜索引擎无法抓取和渲染你的页面,内容再好也没用。

技术 SEO 检查体系

graph TD TECH[技术 SEO] --> CRAWL[可抓取性] TECH --> INDEX[可索引性] TECH --> SPEED[页面速度] TECH --> MOBILE[移动友好] TECH --> STRUCT[结构化数据] CRAWL --> ROBOTS[robots.txt] CRAWL --> SITEMAP[XML Sitemap] CRAWL --> INTERNAL[内链架构] INDEX --> CANONICAL[Canonical 标签] INDEX --> NOINDEX[noindex 控制] SPEED --> CWV[Core Web Vitals] SPEED --> COMPRESS[压缩与缓存] STRUCT --> SCHEMA[Schema.org] STRUCT --> RICH[富媒体摘要] style TECH fill:#e3f2fd,stroke:#1565c0,stroke-width:2px style CWV fill:#fff3e0,stroke:#e65100,stroke-width:2px

Core Web Vitals

"""
Core Web Vitals 评估
"""
from dataclasses import dataclass
@dataclass
class CoreWebVitals:
"""核心网页指标"""
lcp: float   # Largest Contentful Paint (秒)
inp: float   # Interaction to Next Paint (毫秒)
cls: float   # Cumulative Layout Shift
def evaluate(self) -> dict:
"""评估三大指标"""
def grade(value, good, poor, unit=""):
if value <= good:
return f"✅ {value}{unit} (良好 ≤{good}{unit})"
elif value <= poor:
return f"⚠️ {value}{unit} (需改善 ≤{poor}{unit})"
return f"❌ {value}{unit} (差 >{poor}{unit})"
lcp_result = grade(self.lcp, 2.5, 4.0, "s")
inp_result = grade(self.inp, 200, 500, "ms")
cls_result = grade(self.cls, 0.1, 0.25)
scores = [
self.lcp <= 2.5,
self.inp <= 200,
self.cls <= 0.1,
]
return {
"LCP (最大内容渲染)": lcp_result,
"INP (交互响应)": inp_result,
"CLS (布局稳定性)": cls_result,
"通过": f"{sum(scores)}/3",
"整体": "通过" if all(scores) else "未通过",
}
# 评估示例
sites = [
("优秀站点", CoreWebVitals(1.8, 120, 0.05)),
("普通站点", CoreWebVitals(3.2, 350, 0.15)),
("差劲站点", CoreWebVitals(5.5, 600, 0.35)),
]
print("=== Core Web Vitals 评估 ===")
for name, cwv in sites:
result = cwv.evaluate()
print(f"\n{name} [{result['整体']}]")
for k, v in result.items():
if k not in ("通过", "整体"):
print(f"  {k}: {v}")

页面速度优化

优化项 影响 实施难度 效果
图片压缩 WebP LCP 减少 30-50%
懒加载图片 LCP 首屏加速
CDN 加速 LCP 全球加速
压缩 CSS/JS LCP 减少 20%
预连接关键域 LCP 减少 100ms+
延迟非关键 JS INP 交互加速
图片尺寸声明 CLS 消除偏移
字体显示优化 CLS 消除闪烁

结构化数据

"""
Schema.org 结构化数据模板
"""
SCHEMA_TEMPLATES = {
"文章 Article": {
"@context": "https://schema.org",
"@type": "Article",
"headline": "Python 入门教程",
"author": {"@type": "Person", "name": "作者名"},
"datePublished": "2024-01-15",
"dateModified": "2024-03-20",
"description": "零基础学 Python 的完整教程",
"image": "https://example.com/cover.jpg",
},
"FAQ 问答": {
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "Python 适合初学者吗?",
"acceptedAnswer": {
"@type": "Answer",
"text": "是的,Python 语法简洁,非常适合编程初学者。"
},
},
],
},
"产品 Product": {
"@context": "https://schema.org",
"@type": "Product",
"name": "Python 课程",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.8",
"reviewCount": "2350",
},
"offers": {
"@type": "Offer",
"price": "199",
"priceCurrency": "CNY",
},
},
"教程 HowTo": {
"@context": "https://schema.org",
"@type": "HowTo",
"name": "如何安装 Python",
"step": [
{"@type": "HowToStep", "text": "访问 python.org 下载"},
{"@type": "HowToStep", "text": "运行安装程序"},
{"@type": "HowToStep", "text": "勾选 Add to PATH"},
],
},
}
print("=== 结构化数据类型 ===")
for schema_type, template in SCHEMA_TEMPLATES.items():
print(f"\n【{schema_type}】")
print(f"  类型: {template['@type']}")
rich_result = {
"Article": "面包屑 + 作者 + 日期",
"FAQPage": "可展开问答",
"Product": "星级评分 + 价格",
"HowTo": "步骤展示",
}
print(f"  富媒体效果: {rich_result.get(template['@type'], '增强展示')}")

robots.txt 与 Sitemap

"""
robots.txt 和 Sitemap 配置
"""
ROBOTS_TXT = """
# robots.txt 最佳实践
User-agent: *
Allow: /
Disallow: /admin/
Disallow: /api/
Disallow: /search?
Disallow: /tmp/
# 指向 Sitemap
Sitemap: https://example.com/sitemap.xml
"""
SITEMAP_TIPS = {
"基本规则": [
"每个 Sitemap 最多 50,000 个 URL",
"文件大小不超过 50MB (未压缩)",
"使用 lastmod 标明最后修改时间",
"priority 和 changefreq 已被 Google 忽略",
],
"最佳实践": [
"只包含 200 状态码的页面",
"不包含 noindex 页面",
"大站用 Sitemap Index 管理多个文件",
"提交到 Google Search Console",
],
}
print("=== Sitemap 配置建议 ===")
for category, tips in SITEMAP_TIPS.items():
print(f"\n{category}:")
for tip in tips:
print(f"  • {tip}")

技术 SEO 检查工具

工具 检查项 价格
PageSpeed Insights CWV + 速度建议 免费
Google Search Console 索引/CWV/覆盖 免费
Screaming Frog 全站爬取审计 500URL免费
Schema Validator 结构化数据验证 免费
Mobile-Friendly Test 移动端友好检测 免费

行动清单

下一节02-移动端与Core Web Vitals — 移动端优先索引时代,CWV 每提升一档对排名的具体影响。