1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# -*- coding: utf-8 -*- # #author:feko #time:20220526 #description:这是一个集合百度、神马、必应、头条、搜狗、360、谷歌站长URL自动推送工具 # ('百度推送', 'baiduts') # ('神马推送', 'shenmats') # ('必应推送', 'bingts') # ('头条推送 <-- 预留', 'toutiaots') # ('搜狗推送 <-- 预留', 'sougouts') # ('360推送 <-- 预留', 'sots') # ('谷歌推送 <-- 预留', 'googlets') import os,sys import requests import re import json class ZhanZhang: def __init__(self): self.mysite = "xxx" ##填写你的网站,例如www.baidu.com self.baidu_token = "xxx" ##填写你的网站,对应百度的token self.baidu_num = 2000 ##百度API最高提交条数 self.shenma_user_name = "xxx" ##填写你的网站,对应神马用户名 self.shenma_token = "xxxx" ##填写你的网站,对应神马的token self.shenma_num = 10000 ##神马API最高提交条数 self.bing_token = "xxx" ##填写你的网站,对应必应的token self.bing_num = 100 ##必应API最高提交条数 self.shenmasite = "https://%s"%(self.mysite) ##对应http或https def baiduts(self): print("开始百度推送==========================") urls = self.get_urls(self.baidu_num) post_url = 'http://data.zz.baidu.com/urls?site=%s&token=%s'%(self.shenmasite,self.baidu_token) headers = { 'User-Agent': 'curl/7.12.1', 'Host': 'data.zz.baidu.com', 'Content-Type': 'text/plain', 'Content-Length': '83' } s = requests.post(post_url, headers=headers, data=urls).content s = json.loads(s) if 'success' in s.keys(): text = '今日笔趣窝已成功提交{0}条推送到百度站长'.format(s['success']) else: text = '笔趣窝推送失败,请检查原因!' print(text) data = { 'corpid': 'wwb3fce4e752543af1', 'corpsecret': 'OvQyN_Zg-_SCvYeWs3h5zxWewb8uwc5LfjAm-hPnLjc', 'agentid': '1000004', 'text': text } r = requests.post('https://api.htm.fun/api/Wechat/text/', data=data) def shenmats(self): print("开始神马推送==========================") urls = self.get_urls(self.shenma_num) post_url = "https://data.zhanzhang.sm.cn/push?site=%s&user_name=%s&resource_name=mip_add&token=%s"%(self.mysite,self.shenma_user_name,self.shenma_token) headers = { 'User-Agent': 'curl/7.12.1', 'Content-Type': 'text/plain', } response = requests.post(post_url, headers=headers, data=urls).text print(response) tuisong = response data = { 'corpid': 'wwb3fce4e752543af1', 'corpsecret': 'OvQyN_Zg-_SCvYeWs3h5zxWewb8uwc5LfjAm-hPnLjc', 'agentid': '1000004', 'text': tuisong } r = requests.post('https://api.htm.fun/api/Wechat/text/', data=data) def bingts(self): print("开始必应推送==========================") urls = self.get_urls(self.bing_num) urls = urls.strip() urlList = urls.split('\n') post_url = 'https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=%s' % (self.bing_token) ##把列表均分500份,必应限制了每次最多500条 temp_list = [] for i in range(0, len(urlList), 500): temp_list.append(urlList[i:i + 500]) print("总%s条链接" % (len(urlList))) i = 1 for j in temp_list: print("第%s次推送" % (i)) i = i + 1 data = { "siteUrl": self.shenmasite, "urlList": j } r = requests.post(post_url, json=data) print(r.json()) tuisong = r data = { 'corpid': 'wwb3fce4e752543af1', 'corpsecret': 'OvQyN_Zg-_SCvYeWs3h5zxWewb8uwc5LfjAm-hPnLjc', 'agentid': '1000004', 'text': tuisong } r = requests.post('https://api.htm.fun/api/Wechat/text/', data=data) #获取url条数,按倒序获取 def get_urls(self,num): sitemap= requests.get(sitemap_xml).text r = sitemap.replace('</url>', '\n') url = re.findall(r'<loc>(.*)</loc>', r) s = url[-num:] #获取最后几行 new_lines_str = '\n'.join(s) print("获取的是文件最后%s条"%(len(s))) return new_lines_str if __name__ == '__main__': sitemap_xml="xxx"#填写你的xml地图地址 ret = ZhanZhang() ret.baiduts() ret.shenmats() ret.bingts() |
本 脚本通过读取xml地图文件自动通过api将网站推送之百度、神马、必应收录,代码都是经过本人测试可以正常运行,本人不懂python但是通过百度查询修改了一些代码,包括自动发信息至微信,脚本本身没有问题,运行中出现错误请自行百度,本博客只是记录自己日常遇到问题的时候解决办法,以做备份。
阅读全文
评论前必须登录!
立即登录 注册