Hexo使用Requests调用IndexNow协议将网址提交到必应

必应站长新增了一个 IndexNow 功能,当创建、更新或删除url上的网站内容时,使用 Python Requests 第三方库调用 IndexNow 协议来通知必应

生成接口密钥

必应密钥地址:

比如密钥为 1f571e3a4aed400d811a524c70eda337 ,将它下载后,本机上会有一个 1f571e3a4aed400d811a524c70eda337.txt 文件,其内容也是密钥:

1
1f571e3a4aed400d811a524c70eda337

验证网站所有权

首先将 1f571e3a4aed400d811a524c70eda337.txt 文件放在本机 hexo/source 目录下

然后部署:

1
2
3
hexo clean
hexo g
hexo d

最后访问 https://www.gaoyuanqi.cn/1f571e3a4aed400d811a524c70eda337.txt 应该看到:

1
1f571e3a4aed400d811a524c70eda337

其中 https://www.gaoyuanqi.cn/ 是自己的网站域名

提交网址

提交一个网址

1
2
3
4
5
6
7
8
9
10
import requests

bing_url = 'https://www.bing.com/indexnow'
params = {
'key': '1f571e3a4aed400d811a524c70eda337',
'url': 'https://www.gaoyuanqi.cn/hexo-indexnow/',
}

res = requests.get(bing_url, params=params)
print(res.status_code)

说明:

  • bing_url:搜索引擎,这里是必应
  • key:密钥
  • url:要推送的网址

提交一组网址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import requests

bing_url = 'https://www.bing.com/indexnow'
data = {
'host': 'www.gaoyuanqi.cn',
'key': '1f571e3a4aed400d811a524c70eda337',
'keyLocation': 'https://www.gaoyuanqi.cn/1f571e3a4aed400d811a524c70eda337.txt',
'urlList': [
'https://www.gaoyuanqi.cn/hexo-indexnow/',
'https://www.gaoyuanqi.cn/django-csrf/',
]
}

res = requests.post(bing_url, data=data)
print(res.status_code)

说明:

  • bing_url:搜索引擎,这里是必应
  • host:自己的网站域名
  • key:密钥
  • keyLocation:密钥网址,其中 https://www.gaoyuanqi.cn/ 是自己的网站域名
  • urlList:要推送的网址,每行一个网址

查看推送结果

https://www.bing.com/webmasters 中查看 IndexNow

资料