在当前搜索引擎优化(SEO)中,页面被搜索引擎快速收录是站长们尤为关注的问题。传统搜索引擎依赖爬虫周期性抓取网站内容,收录效率低下。而 IndexNow 是一种主动推送协议,允许网站实时将内容更新通知搜索引擎,从而显著提升页面的收录速度。本文将详细介绍如何使用 IndexNow 实现高效索引。

一、注册并验证站点

在实施 IndexNow 之前,建议先在各大搜索引擎的站长平台中注册并验证你的站点,以便更好地监控索引状态和推送效果。以下是几个常用的站长平台:

此外,建议提交网站 Sitemap,有助于搜索引擎更全面地抓取页面内容。

二、使用 IndexNow 实现主动推送

1. 获取 IndexNow API 密钥

访问 IndexNow 官网 或使用第三方在线工具生成一个唯一的 API 密钥(key),该密钥用于验证你的推送身份。

2. 上传密钥文件至网站根目录

将 API 密钥写入一个 .txt 文件,文件名即为密钥本身,然后上传至网站根目录。例如: IndexNow 密钥示意图 如果你的密钥是: ‘74e649aeccf742c192bcaad80acc2647’

则需创建如下文件并上传: https://www.bobobk.com/74e649aeccf742c192bcaad80acc2647.txt 请确保该文件可以通过浏览器直接访问,验证成功后方可继续使用 IndexNow 推送功能。

3. 使用 Python 脚本主动推送 URL

格式 IndexNow 请求格式

以下是一个使用 Python 脚本向 IndexNow 主动推送页面 URL 的示例代码,适用于一次性推送多个页面。

import requests
import json
import sys

def notify_indexnow(urls_str):
    url_list = [url.strip() for url in urls_str.split(",") if url.strip()]
    data = {
        "host": "www.bobobk.com",
        "key": "74e649aeccf742c192bcaad80acc2647",
        "keyLocation": "https://www.bobobk.com/74e649aeccf742c192bcaad80acc2647.txt",
        "urlList": url_list
        }
    headers = {
        "Content-Type": "application/json; charset=utf-8"
        }
    response = requests.post("https://api.indexnow.org/IndexNow", headers=headers, json=data)
    print(f"状态码: {response.status_code}")
    print(f"返回结果: {response.text}")

if len(sys.argv) < 2:
    print('请输入用逗号分隔的 URL 列表作为参数。')
    sys.exit()

urls_input = sys.argv[1]
notify_indexnow(urls_input)

保存为 indexnow.py,然后通过命令行运行,例如:

python indexnow.py https://www.bobobk.com/how-to-improve-index-speed-by-indexnow.html

如果要一次性推送多个页面,请用英文逗号分隔 URL。 查看下日志,

grep how-to-improve-index-speed-by-indexnow.html www.bobobk.com.log

可以看到爬虫来得相当的快。

{"@timestamp":"2025-05-07T11:12:10+08:00","domain":"www.bobobk.com","server_ip":"10.0.0.108","client_ip":"66.249.90.136","cf_ipcountry":"US","size":"7588","responsetime":"0.000","upstreamtime":"","request_method":"GET","url":"/how-to-improve-index-speed-by-indexnow.html","http_user_agent":"Mediapartners-Google","status":"200","referer":""}
{"@timestamp":"2025-05-07T11:12:11+08:00","domain":"www.bobobk.com","server_ip":"10.0.0.108","client_ip":"2600:1f14:748:2301:19e9:f04d:38ff:14ef","cf_ipcountry":"US","size":"7588","responsetime":"0.000","upstreamtime":"","request_method":"GET","url":"/how-to-improve-index-speed-by-indexnow.html","http_user_agent":"ias-or/3.3 (former https://www.admantx.com + https://integralads.com/about-ias/)","status":"200","referer":""}
{"@timestamp":"2025-05-07T11:16:24+08:00","domain":"www.bobobk.com","server_ip":"10.0.0.108","client_ip":"2a09:bac5:3983:16dc::247:b6","cf_ipcountry":"HK","size":"7588","responsetime":"0.000","upstreamtime":"","request_method":"GET","url":"/how-to-improve-index-speed-by-indexnow.html","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36","status":"200","referer":"https://www.bobobk.com/"}
{"@timestamp":"2025-05-07T11:24:39+08:00","domain":"www.bobobk.com","server_ip":"10.0.0.108","client_ip":"95.108.213.91","cf_ipcountry":"RU","size":"7577","responsetime":"0.000","upstreamtime":"","request_method":"GET","url":"/how-to-improve-index-speed-by-indexnow.html","http_user_agent":"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)","status":"200","referer":""}

三、总结

IndexNow 是一个简单而高效的 SEO 工具,适用于想要加快页面收录速度的网站站长。通过生成并部署 API 密钥、配置验证文件、使用脚本或插件推送更新,你可以主动向搜索引擎通知页面的变更,从而实现更快的索引。建议结合站长工具使用,以获得更全面的数据反馈和优化策略。