最新让百度快速收录网站的方法:使用脚本定时提交链接至百度,确保及时收录!

对于新建站的朋友来说,如何让百度快速收录新网站?确实是一个头疼的问题🤦‍!毕竟必应、谷歌,只要在站长工具Webmaster Tools或者Google Search Console中提交网站,就可以被收录了,非常的简单😄。不过不用忧愁,下面就给大家分享一个经过验证可快速收录的方法👇。

百度快速收录

百度搜索资源平台有给官方解决方案:快速收录,登录百度搜索资源平台后可了解快速收录的详细介绍。

登录百度搜索资源平台,百度快速收录

不过快速收录的权限看起来有点神秘,官方给出的方式是:积极参与官方活动,有机会获得,或者站点关联小程序并提交适配规则将有机会优先获得该权限。这说明咱也不敢说什么,只能另寻他法。好在发现普通收录里面的API提交,收录速度也相对sitemap提交或者手动提交要快很多

通过API推送实现快速收录

普通收录里面实际上有三种提交方式,官方给出的区别如下👇

手动提交显然完全没效率,sitemap提交实测,发现收录也非常慢,好多天过去了没反应,所以还是推荐API推送的方式。

使用API推送功能会达到怎样效果?

以下是百度搜索资源平台官方对于API推送效果的说明👇

如何使用百度收录提交API?

官方给出了curl、post、php、ruby四种推送方式的案例,这里推荐使用post推送的方式,原因是post推送一次可提交的数据量更大,而且后续可利用脚本实现自动化推送。

通过API提交链接至百度搜索资源,达到让百度快速收录的效果

post推送的脚本,我这里用python来实现,大家可以根据自己的喜好来,习惯用shell或者php都是可以的。实现起来也非常简单,就是先提取自己站点sitemap中包含的url,然后通过post一次性提交到百度。具体的代码如下👇

import requests, re, time

try:
	# 将www.test.com替换为自己的网站
	response = requests.get('https://www.test.com/sitemap.xml')
	urlList = re.findall(r'<loc>(.+?)<\/loc>', response.text)
	urls = '\n'.join(urlList)
	headers = {
		'User-Agent': 'curl/7.12.1',
		'Host': 'data.zz.baidu.com',
		'Content-Type': 'text/plain',
		'Content-Length': '83',
	}
	# http://data.zz.baidu.com/...这一段是从百度搜索资源后台复制,然后替换成自己的
	response = requests.post('http://data.zz.baidu.com/urls?site=https://www.test.com&token=xxxxxxx', headers=headers, data=urls)
	print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ':' + response.text)
except Exception as e:
	print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ':' + e)

⚠️备注:如果网站没有sitemap的,记得配好这些基础SEO内容,再来考虑收录这些问题。如果你的网站包含多个sitemap文件,可以在外层加一个sitemap列表,然后遍历此列表依次提交即可。具体代码如下👇

import requests, re, time
# 将https://www.test.com/sitemap...替换为自己网站的sitemap
sitemaps = ['https://www.test.com/sitemap1.xml', 'https://www.test.com/sitemap2.xml']

for sitemap in sitemaps:
	try:
		response = requests.get(sitemap)
		urlList = re.findall(r'<loc>(.+?)<\/loc>', response.text)
		urls = '\n'.join(urlList)
		headers = {
			'User-Agent': 'curl/7.12.1',
			'Host': 'data.zz.baidu.com',
			'Content-Type': 'text/plain',
			'Content-Length': '83',
		}
		# http://data.zz.baidu.com/...这一段是从百度搜索资源后台复制,然后替换成自己的
		response = requests.post('http://data.zz.baidu.com/urls?site=https://www.test.com&amp;token=xxxxxxx', headers=headers, data=urls)
		print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ':' + response.text)
	except Exception as e:
		print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ':' + e)

编写好脚本后,可以在服务器上使用命令python3 PushUrlsToBaidu.py试运行,如果收到success的输出,表示推送成功。

2023-06-13 15:10:37:{"remain":89,"success":7}

使用脚本定时向百度推送网站链接

脚本试运行没问题后,就可以设置定时任务,比如:定时每天晚上23:30通过API向百度提交整站所有的链接,确保快速收录。这里利用Linux的crontab来实现定时任务,连接服务器后,输入crontab -e,然后按i进入编辑状态,在末尾添加一条定时任务,然后输入:wq保存并退出。这样就轻松实现了利用脚本及百度官方的API推送,定时向百度推送网站链接,并达到快速收录的效果。

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 

30 15 * * * python3 /www/PushUrlsToBaidu.py >> /www/PushUrlsToBaidu.log 2>&1

如果输入crontab -e后,提示no crontab for root或者no crontab for root - using an empty one,是因为不存在crontab配置文件,并且系统没有设置默认编辑器。只需要退出来,然后输入select-editor,选择vim.basic,然后再输入crontab -e就可以进行配置了。

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /bin/ed

另外,服务器的时区可能是0时区,可以使用date命令查看服务器当前时间,设置的时间与当前时区转换一下即可。

关于crontab的用法参见下图👇,其中user-name可以不设置,如果不设置,会用编辑crontab时使用的用户来执行任务。详细的使用说明可参见Linux crontab 命令

crontab设置定时任务的方法

😊 评论交流
正在加载评论...