【必应】Bing自动提交收录python脚本

一、获取apikey

  • 登录 Bing控制台
  • 获取apikey:打开设置-api访问-api密钥

Screenshot_20220321_172034.png

Screenshot_20220321_172050.png

Screenshot_20220321_172101.png

二、推送脚本

import requests  # 发起请求的库
import re


# 根据站点地图获取链接
def get_urls(sitemap):
    response = requests.get(url=sitemap)
    urls = re.findall('<loc>(.*?)</loc>', response.text)
    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',
                                 })
        print(response.status_code)
    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)
        else:
            print('推送失败:推送配额不足,前往https://www.bing.com/webmasters/submiturl查看配额')


if __name__ == '__main__':
    apiKey = '×××××××××××××××××××××××××××'
    siteUrl = 'https://www.songonline.top/'
    limit = 1000  # 每日提交配额
    urlList = get_urls('https://www.songonline.top/sitemap.xml')[-1000:]  # 提交最新的网站
    submit_bing(site_url=siteUrl, url_list=urlList, api_key=apiKey)

推送结果

Screenshot_20220321_171803.png

三、提高今天的剩余配额

一开始的时候配额只有10,我现在每天有1000配额,对个人博客完全够用。

Screenshot_20220321_172726.png

提高配额方法:

点击了解更多Screenshot_20220321_172918.png

会看到NOTE:

If you think the quota provided is not enough, you can proactively request quota increment by creating a support ticket. We will review your request and update your quota accordingly.

意思是:

如果您认为提供的配额不够,您可以通过创建支持工单主动请求配额增加。我们将审核您的请求并相应地更新您的配额。所以点击链接去请求吧

推送失败

  • 检查自己每日推送配额是否足够
  • 检查站点地图、apikey、网站是否填写正确
最后修改:2022 年 03 月 22 日
如果觉得我的文章对你有用,请随意赞赏