resttemplate post提交json_SEO工具脚本,Python百度普通收录API提交工具
百度收錄問(wèn)題一直是不少渣渣頭痛的問(wèn)題,而官方其實(shí)提供了普通收錄和快速收錄這樣的接口,直接調(diào)用官方api接口,大力出奇跡,你需要相信,你盡管seo,有排名算我輸,不收錄,怎么會(huì)呢,不是給你留了一個(gè)首頁(yè)網(wǎng)址么?以前寫過(guò)熊掌號(hào)的api網(wǎng)址提交,可惜被清退了,也不知道能不能用了。
其實(shí)調(diào)用官方api還是比較簡(jiǎn)單,直接按照官方給出的示例和參數(shù)就能實(shí)現(xiàn),稍微抄抄改改,你也能夠?qū)崿F(xiàn),至于收錄效果,還是前面說(shuō)的那句話,也是國(guó)內(nèi)seo人員的核心,大力出奇跡!
示例代碼
#百度普通收錄 資源提交 API提交 #微信:huguo00289 # -*- coding: UTF-8 -*- import requests import jsondef api(site,token,url):print(f">>> 正在向百度推送鏈接-- {url} ..")post_url=f"http://data.zz.baidu.com/urls?site={site}&token={token}"headers = {'User-Agent': 'curl/7.12.1','Host': 'data.zz.baidu.com','Content-Type': 'text/plain','Content-Length': '83',}response=requests.post(post_url,headers=headers,data=url)req=response.textif "success" in req:print(f"恭喜,{url} -- 百度推送成功!")req_json=json.loads(req)print(f'當(dāng)天剩余的可推送url條數(shù): {req_json["remain"]}')else:print(f"{url} -- 百度推送失敗!下面我們繼續(xù)來(lái)優(yōu)化完善一下!
首先網(wǎng)站地圖,想必大家都知道,sitemap.xml格式文件,里面包含有網(wǎng)站所有的網(wǎng)站,我們可以通過(guò)它來(lái)向搜索引擎提交網(wǎng)業(yè)地址,同時(shí)我們也可以在它身上下功夫,這里我使用的網(wǎng)站地圖文件為老虎地圖所制作。
從sitemap.xml文件讀取到網(wǎng)頁(yè)鏈接地址,使用正則表達(dá)式就可以很輕松的實(shí)現(xiàn)目的!
示例代碼
def get_url(self):with open(self.path,'r',encoding='utf-8') as f:xml_data=f.read()print(">>> 讀取網(wǎng)站地圖文件成功!")urls=re.findall(r'<loc>(.+?)</loc>',xml_data,re.S)print(urls)print(f">>> 共有網(wǎng)頁(yè)鏈接數(shù) :{len(urls)} 條!")return ur考慮到大部分大佬哥的網(wǎng)站鏈接推送數(shù)量可不少,這里應(yīng)用了線程池的技術(shù),多線程推送網(wǎng)址,比較簡(jiǎn)單,復(fù)制粘貼即可完成!
示例代碼
def main(self):urls=self.get_url()try:# 開(kāi)4個(gè) worker,沒(méi)有參數(shù)時(shí)默認(rèn)是 cpu 的核心數(shù)pool = ThreadPool()results = pool.map(self.api,urls)pool.close()pool.join()print(">> 采集所有鏈接百度推送完成!")except Exception as e:print(f'錯(cuò)誤代碼:{e}')print("Error: unable to start thread")完整代碼參考
#百度普通收錄 資源提交 API提交 #微信:huguo00289 # -*- coding: UTF-8 -*- import requests import json,re from multiprocessing.dummy import Pool as ThreadPoolclass Ts():def __init__(self,site,token,path):self.site=siteself.token=tokenself.path=pathdef api(self,url):print(f">>> 正在向百度推送鏈接-- {url} ..")post_url = f"http://data.zz.baidu.com/urls?site={self.site}&token={self.token}"headers = {'User-Agent': 'curl/7.12.1','Host': 'data.zz.baidu.com','Content-Type': 'text/plain','Content-Length': '83',}response = requests.post(post_url, headers=headers, data=url)req = response.textif "success" in req:print(f"恭喜,{url} -- 百度推送成功!")req_json = json.loads(req)print(f'當(dāng)天剩余的可推送url條數(shù): {req_json["remain"]}')else:print(f"{url} -- 百度推送失敗!")return Nonedef get_url(self):with open(self.path,'r',encoding='utf-8') as f:xml_data=f.read()print(">>> 讀取網(wǎng)站地圖文件成功!")urls=re.findall(r'<loc>(.+?)</loc>',xml_data,re.S)print(urls)print(f">>> 共有網(wǎng)頁(yè)鏈接數(shù) :{len(urls)} 條!")return urlsdef main(self):urls=self.get_url()try:# 開(kāi)4個(gè) worker,沒(méi)有參數(shù)時(shí)默認(rèn)是 cpu 的核心數(shù)pool = ThreadPool()results = pool.map(self.api,urls)pool.close()pool.join()print(">> 采集所有鏈接百度推送完成!")except Exception as e:print(f'錯(cuò)誤代碼:{e}')print("Error: unable to start thread")if __name__ == '__main__':site="網(wǎng)站地址"token="秘鑰"path=r"網(wǎng)站地圖文件存儲(chǔ)路徑"spider=Ts(site,token,path)總結(jié)
以上是生活随笔為你收集整理的resttemplate post提交json_SEO工具脚本,Python百度普通收录API提交工具的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql使用的索引长度_MySQL索引
- 下一篇: python 元类 type_pytho