前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用Python写一个百度POST实时推送工具

用Python写一个百度POST实时推送工具

作者头像
ITJoker
发布2022-08-30 11:15:03
3890
发布2022-08-30 11:15:03
举报
文章被收录于专栏:ITJoker的吹逼专栏

想抄就抄吧

以下是代码

代码语言:javascript
复制
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'
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-12-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 以下是代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档