百度sitemap Api自动提交收录方法,本文使用python提交。
首先先将网站的sitemap地图(网站根目录自己生成的sitemap.xml)转换为txt文本的一条条链接,然后再把txt文本的链接通过api提交百度站长收录。
百度官网的API代码示例如下:
根据百度的接口提示,我们可以做如下方法:
一、新建py_url.py文件读取链接,存入txt文档。
#coding=utf-8
import urllib
import urllib.request
import re
url='http://www.budinghua.com/sitemap.xml'
html=urllib.request.urlopen(url).read()
html=html.decode('utf-8')
r=re.compile(r'(http://www.budinghua.com.*?\.html)')//匹配www.budinghua.com网站的所有html链接
big=re.findall(r,html)
clean_xml_txt=open("x:/xxx/xxx/xxx/sitemap.txt", 'w').close()//先清空再写入
for j, i in enumerate(big):
print(i)
if j > 1:
op_xml_txt=open('x:/xxx/xxx/xxx/sitemap.txt','a')//读取链接到txt,路径自己喜欢就