因为小雨在吾爱破解的会员等级不够,无法实时接收到新消息提醒,所以发布了一个 python 定时通知的方式,也首发在吾爱破解论坛上,本文只是以吾爱破解论坛消息提醒功能为例子来编写代码
这个消息提醒功能,原则上这种办法适合所有网站的消息提醒功能,大家可以在这个基础上进行发散开发(学习一定要学会举一反三,不然就是个榆木脑袋了)
# -*- coding: utf8 -*- import json import requests import bs4 import time token = 'your token'#在发送消息页面可以找到 def pushinfo(text,desp): headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', 'ContentType': 'text/html' } notifyurl = 'https://api.ossec.cn/v1/send?token=%s&topic=%s&message=%s'%(token,text,desp) requests.get(notifyurl,headers=headers) def main_handler(event, context): headers={ 'Cookie': 'your cookie', 'ContentType':'text/html;charset=gbk', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36', } html=requests.get('https://www.52pojie.cn',headers=headers) bsObj =bs4.BeautifulSoup(html.content,'html.parser') parent=bsObj.find('ul',id='myprompt_menu') num = len(parent.find_all('li')) if num > 3: text = u'{0} 吾爱破解有新消息回复'.format(time.strftime("%Y-%m-%d %H:%M", time.localtime())) msgNum = parent.find('span',class_='rq').get_text() pushinfo(text, "消息数:" + msgNum + "条") # else: # pushinfo("暂无消息",0)
使用说明:
1、腾讯云云函数设置定时任务,比如 20 分钟或者 1 小时 或者一天,频率自己设置,。鉴于本版块有很多布置云函数的帖子,我就不赘述了。
2、通知选择的是欧赛信令,相比于 server 酱来说,目前可以显示正文详情,可能是用的人少吧,反正能满足我的日常使用,大家可以自由选择。
3、代码中的 token 和 cookie 需要更改为自己的
代码功能原理:登录后判断网站消息提醒处对应 div 的子元素个数,当然了这个是通过对比后发现的。
没有消息时的 html 结构
<ul id="myprompt_menu" class="p_pop" style="position: absolute; z-index: 301; left: 1305.96px; top: 72.6px;" disautofocus="true" initialized="true"> <li><a href="home.php?mod=space&do=pm" id="pm_ntc" style="background-repeat: no-repeat; background-position: 0 50%;"><em class="prompt_news_0"></em>消息</a></li> <li><a href="home.php?mod=follow&do=follower"><em class="prompt_follower_0"></em>新听众</a></li> <li class="ignore_noticeli"><a href="javascript:;" onclick="setcookie('ignore_notice', 1);hideMenu('myprompt_menu')" title="暂不提醒"><em class="ignore_notice"></em></a></li> </ul>
有消息时候时的 html 结构
<ul id="myprompt_menu" class="p_pop" style="position: absolute; z-index: 301; left: 1268.88px; top: 72.6px;" disautofocus="true" initialized="true"> <li><a href="home.php?mod=space&do=pm" id="pm_ntc" style="background-repeat: no-repeat; background-position: 0 50%;"><em class="prompt_news_0"></em>消息</a></li> <li><a href="home.php?mod=follow&do=follower"><em class="prompt_follower_0"></em>新听众</a></li> <li><a href="home.php?mod=space&do=notice&view=system"><em class="notice_system"></em>系统提醒(<span class="rq">1</span>)</a></li> <li class="ignore_noticeli"><a href="javascript:;" onclick="setcookie('ignore_notice', 1);hideMenu('myprompt_menu')" title="暂不提醒"><em class="ignore_notice"></em></a></li> </ul>
效果图:
你可能对这些文章感兴趣:
- ChatGPT api 用了一两天突然无法返回数据的解决办法,附国内免翻网站
- Could not find a version that satisfies the requirement win32clipboard报错解决方法
- 免插件使用火山引擎veImageX加速wordpress站点
- 小程序云开发系列教程:注册小程序
- WordPress插件头注释申明
- 淘宝天猫平时和双11购物如何省钱
- 分享一个下载youtube视频封面图的工具网站
- 分享一个windows10万能文件预览工具:QuickLook
- mirai机器人插件:淘口令转换插件分享
- 淘客二合一链接是什么?
- mirai机器人插件:影视搜索插件微搜片分享
- 宝塔面板无法记录网站日志解决办法
- wordpress插件WP Term Order分类排序
- wordpress后台链接添加nofollow选项
如有疑问,请前往问答中心反馈!
反馈