百度搜索收录方式(Api提交的方式)

快速抓取

目前百度搜索资源平台快速收录,普通用户已经没有此权益(需要充值VIP),为此百度给普通用户提供的普通收录方式。

1、百度快速抓取权益要求(需要VIP)

(1)站点成为搜索资源平台VIP合作伙伴,我们会自动赋予权益,参考《VIP俱乐部介绍及申请》。需要时VIP,未通过站点重复申请不予评估。
      (2)站点非VIP,请关注百度搜索资源平台,积极参与活动,通过活动获得权益。


普通收录

使用说明

  • 1、普通收录工具可以向百度搜索主动推送资源,缩短爬虫发现网站链接的时间,不保证收录和展现效果。
  • 2、API提交和手动提交共享配额,sitemap提交配额不与其他方式共享,具体配额以站点页面显示数据为准 。配额不可累计,当日有效。
  • 3、若链接存在跳转关系,请直接提交跳转后链接。如网站换域名,需提交新域名资源;进行HTTPS改造页面,请提交HTTPS资源。

py脚本实现百度搜索引擎收录

接下来将通过py代码脚本实现,百度搜索引擎普通收录(Api提交的方式)

接口参数地址(这里参数说明就不一一介绍了)

详见 :

https://ziyuan.baidu.com/linksubmit/index?site=https://www.aigc.cloud/

1、读取站点sitemap.txt(需要将url先存入sitemap.txt文档中,py脚本读取)

示例sitemap.txt文档中的大致内容如下
https://www.aigc.cloud/wp-sitemap-posts-post-1.xml
https://www.aigc.cloud/wp-sitemap-posts-page-1.xml
https://www.aigc.cloud/wp-sitemap-posts-sites-1.xml
https://www.aigc.cloud/wp-sitemap-posts-app-1.xml
https://www.aigc.cloud/wp-sitemap-posts-bulletin-1.xml
https://www.aigc.cloud/wp-sitemap-taxonomies-category-1.xml
1.1 py代码脚本
from __future__ import unicode_literals, absolute_import

import requests


#主动推送站点链接到百度,读取sitemap.txt 文件,每行一个url
class BaiduLinkSubmit(object):
    def __init__(self, site_domain, sitemap_file, baidu_token):
        self.site_domain = site_domain
        self.sitemap_file = sitemap_file
        self.baidu_token = baidu_token
        self.url_list = []

    def read_sitemap(self):
        print('开始读取sitemap文件')
        with open(self.sitemap_file, 'r') as f:
            self.url_list = [line.strip() for line in f if line.strip()!= '']
        print(f'抓取到{len(self.url_list)}项URL链接')

    def submit(self):
        url = 'http://data.zz.baidu.com/urls?site=%s&token=%s' % (self.site_domain, self.baidu_token)
        headers = {
            'Content-Type': 'text/plain'
        }
        data = '\n'.join(self.url_list)
        r = requests.post(url, headers=headers, data=data)
        data = r.json()
        print(f'成功推送的ur1条数:{data.get("success", "")}')
        print(f'当天剩余的可推送ur1条数:{data.get("remain", "")}')
        not_same_site = data.get('not_same_site', [])
        not_valid = data.get('not_valid', [])
        if len(not_same_site) > 0:
            print('由于不是本站ur1而未处理的ur1列表')
            for t in not_same_site:
                print(t)
        if len(not_valid) > 0:
            print('不合法的ur1列表')
            for t in not_valid:
                print(t)

def main():
    # 需要修改为需要推送的域名
    site_domain = 'https://www.agic.cloud'
    # sitemap.txt 的文件路径
    sitemap_file ='sitemap.txt'
    # 在站长平台申请的推送用的准入密钥
    # 在百度站长平台可以查找到
    baidu_token = ''
    app = BaiduLinkSubmit(site_domain, sitemap_file, baidu_token)
    app.read_sitemap()
    app.submit()

if __name__ == '__main__':
    main()

2、py脚本直接站点sitemap.xml,获取其中的url并访问

sitemap.xml示例:
https://www.aigc.cloud/wp-sitemap.xml
py代码脚本
from __future__ import unicode_literals, absolute_import

import requests
import xmltodict


# 主动推送站点链接到百度,读取sitemap.xml
class BaiduLinkSubmit(object):
    def __init__(self, site_domain, sitemap_url, baidu_token):
        self.site_domain = site_domain
        self.sitemap_url = sitemap_url
        self.baidu_token = baidu_token

    def parse_sitemap(self):
        self.url_list = []
        print('开始抓取sitemap')
        print('访问 %s' % self.sitemap_url)
        r = requests.get(self.sitemap_url)
        data = xmltodict.parse(r.text)
        self.url_list = [t['loc'] for t in data['urlset']['url']]
        print('抓取到%s项URL链接' % len(self.url_list))

    def submit(self):
        url = 'http://data.zz.baidu.com/urls?site=%s&token=%s' % (self.site_domain, self.baidu_token)
        headers = {
            'Content-Type': 'text/plain'
        }
        data = '\n'.join(self.url_list)
        r = requests.post(url, headers=headers, data=data)
        data = r.json()
        print('成功推送的ur1条数:%s' % data.get('success', ''))
        print('当天剩余的可推送ur1条数:%s' % data.get('remain', ''))
        not_same_site = data.get('not_same_site', [])
        not_valid = data.get('not_valid', [])
        if len(not_same_site) > 0:
            print('由于不是本站ur1而未处理的ur1列表')
        if len(not_valid) > 0:
            print('不合法的ur1列表')
            for t in not_same_site:
                print(t)
            for t in not_valid:
                print(t)

def main():
    # 需要修改为自己的域名
    site_domain ='https://www.aigc.cloud'
    # sitemap.xml 的地址
    sitemap_url = 'https://www.aigc.cloud/wp-sitemap.xml'
    # 在站长平台申请的推送用的准入密钥
    # 在百度站长平台可以查找到
    baidu_token = 'your_baidu_token'
    app = BaiduLinkSubmit(site_domain, sitemap_url, baidu_token)
    app.parse_sitemap()
    app.submit()

if __name__ == '__main__':
    main()

总结

最后在服务器中执行以上脚本,就可以实现主动向百度搜索引擎推送你的网址内容,不用等待百度蜘蛛爬虫爬取,实现快速收录。

好了,本期内容就分享到这,点个关注,共同交流。(脚本仅供学习交流)