# -*- coding: utf-8 -*- import json import os from time import sleep from urllib import parse import schedule import time import requests import re class Pusher(object): def __init__(self): print('init_') def getSitemapIndex(self, sitemapIndexUrl): print('getSitemapIndex:' + sitemapIndexUrl) result = requests.get(sitemapIndexUrl) print(result) # print(result.content) sitemapUrls = re.findall('<loc>(.*?)</loc>', result.content.decode('utf-8'), re.S) print(sitemapUrls) return sitemapUrls def getSitemap(self, sitemapUrl): print("getSitemap:" + sitemapUrl) result = requests.get(sitemapUrl) self.urls = re.findall('<loc>(.*?)</loc>', result.content.decode('utf-8'), re.S) print(self.urls) def postBaidu(self): print("postBaidu:=================================") header_baidu = { "User-Agent": "curl/7.12.1", "Host": "data.zz.baidu.com", "Content-Type": "text/plain", "Content-Length": "83" } file = open('push_baidu.txt', 'a+') file.seek(0, 0) # 游标移动到第一行,继续读,否则读取到的是空 content = file.read() # self.f.close() print("content:" + content) for url in self.urls: if url in content: print("已经推送过:" + url) pass else: try: result = requests.post(push_baidu, data=url, headers=header_baidu) print(url + result.content.decode('utf-8')) if '"success":1' in result.content.decode('utf-8'): file.write(url + '\n') file.flush() if '{"remain":0' in result.content.decode('utf-8'): break # break except Exception as e: print(e) sleep(1) file.close() def postShenma(self): print("postShenma:=================================") header_baidu = { "User-Agent": "curl/7.12.1", "Host": "data.zhanzhang.sm.cn", "Content-Type": "text/plain" } file = open('push_shenma.txt', 'a+') file.seek(0, 0) # 游标移动到第一行,继续读,否则读取到的是空 content = file.read() # self.f.close() print("content:" + content) data = '' for url in self.urls: if url in content: print("已经推送过:" + url) pass else: data = data + url + '\n' try: result = requests.post(push_shenma, data=data, headers=header_baidu) print("url:" + url) print("status_code:" + str(result.status_code)) print("content:" + result.content.decode('utf-8')) if str(result.status_code) == "200": content = json.loads(result.content.decode('utf-8')) print("returnCode " + str(content['returnCode'])) if str(content['returnCode']) == "200": file.write(data + '\n') file.flush() except Exception as e: print(e) sleep(1) file.close() def postSougou(self): print("postSougou:=================================") header_baidu = { "User-Agent": "Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15", "Host": "sogou.com", "Content-Type": "application/x-www-form-urlencoded" } file = open('push_sogou.txt', 'a+') file.seek(0, 0) # 游标移动到第一行,继续读,否则读取到的是空 content = file.read() # self.f.close() print("content:" + content) for url in self.urls: if url in content: print("已经推送过:" + url) pass else: try: result = requests.post(push_sogou, data={"source": "1", "site_type": "1", "Shoulu": {"webAdr": url, "email": "932888148@qq.com", "reason": "网站收录不正常,恳请收录!"}}, headers=header_baidu) print(url + result.content.decode('utf-8')) except Exception as e: print(e) sleep(1) file.close() def get360Token(self, url, key): n = list(url) n.reverse() r = list(key) i = [] # for ($s=0, $o=16;$s < $o;$s++) for s in range(0, 16): if n[s] is None: i.append(r[s]) else: i.append(r[s] + n[s]) return ''.join(i) def run(self, sitemapUrl): self.getSitemap(sitemapUrl) self.postBaidu() urlSitemap = '' # Your sitemap url, like 'http://blog.kxrr.us/index.php/sitemap' urlPost = '' # Your Baidu API, like 'http://data.zz.baidu.com/urls?site=blog.kxrr.us&token=xxxxxxxxxxxx' push_baidu = 'http://data.zz.baidu.com/urls?site=meishih.com&token=' # 定义你要周期运行的函数 def job(): print("I'm working...") pusher = Pusher() sitemapUrls = pusher.getSitemapIndex("http://meishih.com/sitemap_index.xml") for sitemapUrl in sitemapUrls: pusher.run(sitemapUrl) schedule.every().day.at("17:32").do(job) # 每天在 10:30 时间点运行 job 函数 if __name__ == '__main__': # while True: # schedule.run_pending() # 运行所有可以运行的任务 # time.sleep(10) job() # pusher = Pusher() # pusher.postBingQuota() # pusher.getSitemapIndex('meishih.com/sitempa_index.xml') # print(pusher.get360Token("http://meishih.com/", "d182b3f28525f2db83acfaaf6e696db"))# pusher = Pusher() # pusher.postBingQuota() # pusher.getSitemapIndex('meishih.com/sitempa_index.xml') # print(pusher.get360Token("http://meishih.com/", "d182b3f28525f2db83acfaaf6e696db"))
相关推荐
【python】 AI绘画对接百度API源码 可视化 【python】 AI绘画对接百度API源码 可视化 【python】 AI绘画对接百度API源码 可视化 【python】 AI绘画对接百度API源码 可视化 【python】 AI绘画对接百度API源码 可视化 ...
下面小编就为大家分享一篇Python爬虫实例_利用百度地图API批量获取城市所有的POI点,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
百度语音识别API ,python语言用,百度语音识别API ,python语言用,百度语音识别API ,python语言用,百度语音识别API ,python语言用,
利用百度api接口,根据excel中的地址,批量获取该地址的百度经纬度,主要注意的是,获得的坐标是百度坐标系,而不是wgs84.
python百度网盘纯代码分片上传目录文件 不依赖第三方, AppKey等信息需要自己去申请。然后获取code码就可以一直使用。
自动从txt读取flag并提交指定平台python脚本,AWD比赛专用,可以自定义内容,批量提交等,确保速度
opencv-python api手册.rar
千锋教育 Python 视频教程 www.qfedu.com/video 做真实的自己-用良心做教育 python 入门配套教程百度云分享 Python 由于其简单,快速,库丰富的特点在国内使用的越来越广泛。最 近几年它出现了爆发式的增长,而且与...
基于python的百度网盘批量转存工具.zip基于python的百度网盘批量转存工具.zip基于python的百度网盘批量转存工具.zip基于python的百度网盘批量转存工具.zip基于python的百度网盘批量转存工具.zip基于python的百度网盘...
Python自动化测试教程,从零基础开始手把手有详细的步骤教你怎么写自动化测试用例。测试人员大多是希望利用编程诧言来帮劣他实现自劢化的测试,而丌需要花费大量的精力来学习一门编程诧言,所以在本文档中丌会过多...
Python作业提交系统功能介绍:这是一个基于Python Flask框架编写的Web应用,用于收集课程的班级作业。 Python作业提交系统功能介绍:这是一个基于Python Flask框架编写的Web应用,用于收集课程的班级作业。 Python...
史上最简单易学的python自动化测试教程从基础与实战【柠檬班软件测试】 202x-11-11 演讲人 史上最简单易学的Python自动化测试教程从基础与实战【柠檬班软件测试】PPT模板全文共13页,当前为第1页。 1如何使用python...
Python自动化办公(2021最新版!有源代码 ,~).zip
python自动化办公手册pdf ,更多Pyhon自动化学习可参考我的这篇文章:https://blog.csdn.net/qq_36816848/article/details/118077191
selenium2 python自动化测试 PDF学习 本PDF可以学习到如何进行Web自动化测试以多线程运行测试集,自动生成测试报告,最后完成后发送邮件等功能。
百度翻译API接口Python2版,欢迎下载!
利用Python爬虫批量下载百度图库图片
3dmax python api 绝对猛料3dmax python api 绝对猛料3dmax python api 绝对猛料3dmax python api 绝对猛料3dmax python api 绝对猛料3dmax python api 绝对猛料3dmax python api 绝对猛料
人们都喜欢最好的东西,想找 Python 视频教程百度网盘?在这呢。 千锋 Python 基础教程:http://pan.baidu.com/s/1qYTZiNE Python 课程教学高手晋级视频总目录: http://pan.baidu.com/s/1hrXwY8k Python 课程 ...
Python项目案例开发从入门到实战源代码第4章 调用百度API应用——小小翻译器