进入必应站长:https://www.bing.com/webmasters/indexnow

右上角 设置—>API访问—>查看API密钥

Python 脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
import re
import json

# 需要修改的部分
# apiKey
apiKey = '上面获取的apiKey'
# 站点网址
siteUrl = 'https://blog.365day.top/'
# 推送最新的20个页面
limit = 20
# sitemap.xml地址
sitemapUrl = 'https://blog.365day.top/sitemap.xml'


# 根据站点地图获取链接
def get_urls(sitemap):
response = requests.get(url=sitemap)
urls = re.findall('<loc>(.*?)</loc>', response.text)
# 反向排序,适合我的情况
urls.sort(reverse=True)
return urls

# 提交到必应
def submit_bing(site_url: str, url_list: list, api_key: str):
try:
response = requests.post(url=f"https://ssl.bing.com//webmaster/api.svc/json/SubmitUrlbatch?apikey={api_key}",
json={
'siteUrl': site_url,
'urlList': url_list
},
headers={
'Host': 'ssl.bing.com',
'Content-Type': 'application/json; charset=utf-8',
})
except Exception as e:
print(e)
finally:
if response.status_code == 200 and response.json().get('d') is None:
print('推送成功:')
for i in url_list:
print(i)
get_Quota(site_url,api_key)
else:
print('推送失败:推送配额不足!')
get_Quota(site_url,api_key)

# 获取剩余配额
def get_Quota(site_url: str, api_key: str):
try:
response = requests.get(url=f"https://ssl.bing.com//webmaster/api.svc/json/GetUrlSubmissionQuota?siteUrl={site_url}&apikey={api_key}",
headers={
'Host': 'ssl.bing.com',
'Content-Type': 'application/json; charset=utf-8',
})
result = json.loads(response.text)
DailyQuota = result.get('d').get('DailyQuota')
MonthlyQuota = result.get('d').get('MonthlyQuota')
print("今日剩余可推送:" , DailyQuota , "条")
print("本月剩余可推送:" , MonthlyQuota , "条")
except Exception as e:
print(e)


if __name__ == '__main__':
urlList = get_urls(sitemapUrl)[-limit:]
submit_bing(site_url=siteUrl, url_list=urlList, api_key=apiKey)