用Python写一个百度POST实时推送工具
Python,一个,百度,POST,实时,推送,工具
2025-03-25 08:59:30 时间
想抄就抄吧
以下是代码
import urllib,urllib2
import json,time,re
# 转载请注明出处
def GetURL(geturl,pat):#获取文章的列表
response = urllib2.urlopen(geturl).read()
result = re.findall(pat,response)
return result
# Write By ITJoker
# Domain:https://www.itjoker.cn
def put(host,token,pyload):#提交内容
url = r'http://data.zz.baidu.com/urls?site=' + host + '&token='+token
headers = {
'Content-Type': 'text/plain',
}
data = pyload #urllib.urlencode(pyload)
request = urllib2.Request(url,data,headers=headers)
try:
response = urllib2.urlopen(request)
json_data = json.loads(response.read())
print "Total:"+ str(json_data['remain'])
except urllib2.URLError,e:
print e.reason
def update(host,token,pyload):#更新内容
url = r'http://data.zz.baidu.com/update?site=' + host + '&token='+token
headers = {
'Content-Type': 'text/plain',
}
data = pyload #urllib.urlencode(pyload)
request = urllib2.Request(url,data,headers=headers)
try:
response = urllib2.urlopen(request)
json_data = json.loads(response.read())
print "Result:"+ str(json_data)
except urllib2.URLError,e:
print e.reason
def delete(host,token,pyload): #删除内容
url = r'http://data.zz.baidu.com/del?site=' + host + '&token='+token
headers = {
'Content-Type': 'text/plain',
}
data = pyload #urllib.urlencode(pyload)
request = urllib2.Request(url,data,headers=headers)
try:
response = urllib2.urlopen(request)
json_data = json.loads(response.read())
print "Total:"+ str(json_data['remain'])
except urllib2.URLError,e:
print e.reason
host = "这里填写你要推送的URL"
token = "这里填写Token"
method =["http://","https://"]
domain_url = method[1]+host+"/atom.xml" #获取文章的目录,我这里采用获取RSS的方法来匹配
pat = "<link href=(.*?)>"
old_time = time.time()
urls = GetURL(domain_url,pat)
res =""
for i in range(len(urls)):
res += urls[i].replace('"','')+"\n"
put(host,token,res)
new_time = time.time()
print 'used_time: '+str(int((new_time-old_time)*1000))+'ms'
相关文章
- python下mqtt服务器的搭建_搭建MQTT服务器
- Python 哈希表查询_进入<哈希函数>为结界的世界
- Python 命令行参数的3种传入方式
- python测试框架unittest如何设置用例优先级_python 的 unittest 测试框架中的测试依赖怎么解决呢…[通俗易懂]
- 不用学Python的自动化办公 确定不来看看?
- 8000 字 Python 数据可视化实操指南
- Python实现物流管理系统
- 做自动化测试选择Python还是Java?
- 最美圣诞树!用Python画棵雪夜圣诞树送给你
- 我用 Python 给老板写了封拒绝不了的辞职信
- 我用 Python 画了一盘粽子送给大家
- Python 上下文管理及 with 语句的实用技巧
- 分类变量的卡方检验(python实现&SPSS实现)「建议收藏」
- Python自动给抖音小姐姐视频点赞
- 如何设置python的环境变量_anaconda环境变量手动设置
- python小知识点-exec的local
- 不止短信!教你用 Python 发送告警通知到微信
- Python-方法反射
- 工具推荐|利用python-cdo高效处理气象数据
- python 函数、运算符以及运算符优先级