當前位置:
首頁 >
resttemplate post提交json_SEO工具脚本,Python百度普通收录API提交工具
發布時間:2024/9/27
36
豆豆
生活随笔
收集整理的這篇文章主要介紹了
resttemplate post提交json_SEO工具脚本,Python百度普通收录API提交工具
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
百度收錄問題一直是不少渣渣頭痛的問題,而官方其實提供了普通收錄和快速收錄這樣的接口,直接調用官方api接口,大力出奇跡,你需要相信,你盡管seo,有排名算我輸,不收錄,怎么會呢,不是給你留了一個首頁網址么?以前寫過熊掌號的api網址提交,可惜被清退了,也不知道能不能用了。
其實調用官方api還是比較簡單,直接按照官方給出的示例和參數就能實現,稍微抄抄改改,你也能夠實現,至于收錄效果,還是前面說的那句話,也是國內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'當天剩余的可推送url條數: {req_json["remain"]}')else:print(f"{url} -- 百度推送失敗!下面我們繼續來優化完善一下!
首先網站地圖,想必大家都知道,sitemap.xml格式文件,里面包含有網站所有的網站,我們可以通過它來向搜索引擎提交網業地址,同時我們也可以在它身上下功夫,這里我使用的網站地圖文件為老虎地圖所制作。
從sitemap.xml文件讀取到網頁鏈接地址,使用正則表達式就可以很輕松的實現目的!
示例代碼
def get_url(self):with open(self.path,'r',encoding='utf-8') as f:xml_data=f.read()print(">>> 讀取網站地圖文件成功!")urls=re.findall(r'<loc>(.+?)</loc>',xml_data,re.S)print(urls)print(f">>> 共有網頁鏈接數 :{len(urls)} 條!")return ur考慮到大部分大佬哥的網站鏈接推送數量可不少,這里應用了線程池的技術,多線程推送網址,比較簡單,復制粘貼即可完成!
示例代碼
def main(self):urls=self.get_url()try:# 開4個 worker,沒有參數時默認是 cpu 的核心數pool = ThreadPool()results = pool.map(self.api,urls)pool.close()pool.join()print(">> 采集所有鏈接百度推送完成!")except Exception as e:print(f'錯誤代碼:{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'當天剩余的可推送url條數: {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(">>> 讀取網站地圖文件成功!")urls=re.findall(r'<loc>(.+?)</loc>',xml_data,re.S)print(urls)print(f">>> 共有網頁鏈接數 :{len(urls)} 條!")return urlsdef main(self):urls=self.get_url()try:# 開4個 worker,沒有參數時默認是 cpu 的核心數pool = ThreadPool()results = pool.map(self.api,urls)pool.close()pool.join()print(">> 采集所有鏈接百度推送完成!")except Exception as e:print(f'錯誤代碼:{e}')print("Error: unable to start thread")if __name__ == '__main__':site="網站地址"token="秘鑰"path=r"網站地圖文件存儲路徑"spider=Ts(site,token,path)總結
以上是生活随笔為你收集整理的resttemplate post提交json_SEO工具脚本,Python百度普通收录API提交工具的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql使用的索引长度_MySQL索引
- 下一篇: python 元类 type_pytho