当前位置: 首页 > web >正文

掉线监测-tezos rpc不能用,改为残疾网页监测

自从有了编程伴侣,备忘的需求变得更低了,明显不担心记不住语法需要记录的情景。然而还是保持习惯,就当写日记吧,记录一下自己时不时在瞎捣腾啥。

tm,好人谁记日记。

 就是监控灰色各自前紧挨着出现了多少红色格子。一共查灰色格子前12个格子,如果红色格子大于了8个,就得上去服务器看一眼。脚本写完用个定时程序隔1小时查查,足够了。

说起来,为了这个自己的项目,写了好几个监控,但是程序本身的log都防不住,出现的问题是专门跑项目的go程序之类的,日志里面居然不报错,但是明明就是漏了。

以下python脚本底层是在折腾爬虫针对动态页面的svg加载后元素变化的抓取,以及smtp邮件发送。放个雏形,这个不能线上用,不然false alarm太多。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import re
import time
import osimport smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.image import MIMEImage# ===== 配置区 =====
SMTP_SERVER = "smtp.sohu.com"  # 邮箱服务商SMTP地址
PORT = 465                     # 端口号(SSL用465,TLS用587)
SENDER_EMAIL = "wawa@sohu.com"  # 发件邮箱
SENDER_PASSWORD = "123"  # 邮箱授权码(非登录密码)
RECIPIENT_EMAIL = "567@yahoo.com"  # 收件邮箱
# ==================def send_email(subject, content, is_html=False, attachments=None, images=None):"""发送邮件核心函数"""try:# 1. 创建邮件容器msg = MIMEMultipart()msg["From"] = SENDER_EMAILmsg["To"] = RECIPIENT_EMAILmsg["Subject"] = subject# 2. 添加邮件正文content_type = "html" if is_html else "plain"msg.attach(MIMEText(content, content_type, "utf-8"))# 3. 添加附件(可选)if attachments:for file_path in attachments:with open(file_path, "rb") as file:part = MIMEApplication(file.read())part.add_header("Content-Disposition", f"attachment; filename={file_path.split('/')[-1]}")msg.attach(part)# 4. 添加图片(可选)if images:for img_path, cid in images.items():  # cid用于HTML中引用with open(img_path, "rb") as img_file:img = MIMEImage(img_file.read())img.add_header("Content-ID", f"<{cid}>")msg.attach(img)# 5. 连接SMTP服务器并发送with smtplib.SMTP_SSL(SMTP_SERVER, PORT) as server:  # SSL连接server.login(SENDER_EMAIL, SENDER_PASSWORD)server.sendmail(SENDER_EMAIL, RECIPIENT_EMAIL, msg.as_string())print("✅ 邮件发送成功")except Exception as e:print(f"❌ 邮件发送失败: {str(e)}")def fetch_dynamic_rect_ids_with_gecko():# 配置Firefox无头模式firefox_options = Options()firefox_options.add_argument("--headless")  # 无界面运行firefox_options.set_preference("dom.webnotifications.enabled", False)  # 禁用通知弹窗# 设置geckodriver路径(需提前下载并配置)# 下载地址:https://github.com/mozilla/geckodriver/releases# gecko_path = os.path.join(os.getcwd(), "geckodriver")  # Linux/macOSgecko_path = "/usr/local/bin/geckodriver"# gecko_path = r"C:\path\to\geckodriver.exe"  # Windows路径示例try:# 初始化geckodriver服务service = Service(executable_path=gecko_path)driver = webdriver.Firefox(service=service, options=firefox_options)driver.get("https://niyaojiankongde.wangzhan")time.sleep(12)driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")  # 滚动到底部,用来欺骗服务器,是人在动# 或模拟点击:driver.find_element(By.CSS_SELECTOR, "#trigger_button").click()# 显式等待SVG内容渲染(关键步骤)wait = WebDriverWait(driver,18)rects = wait.until(EC.presence_of_all_elements_located((By.XPATH,"//*[local-name()='svg']//*[local-name()='rect']")))#WebDriverWait(driver, 15).until(#    EC.presence_of_all_elements_located((By.TAG_NAME, "rect")) # 此处疑似无效#    #EC.visibility_of_element_located((By.TAG_NAME,"rect")) # 此处疑似无效#    #EC.element_to_be_clickable((By.TAG_NAME,"rect"))#)#rects = driver.find_elements(By.TAG_NAME, "rect")driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")  # 滚动到底部,用来欺骗服务器,是人在动time.sleep(1)signal_mail = Falsefirst_grey_id = "null"match_red_ids = []pattern_grey = re.compile(r'fill:\s*rgb\(\s*100\s*,\s*\d+\s*,\s*\d+\s*\)')  # 匹配r=100的RGB样式,这是灰色pattern_red =  re.compile(r'fill:\s*rgb\(\s*176\s*,\s*\d+\s*,\s*\d+\s*\)')  # 匹配r=176的RGB样式,这是红色特征for rect in rects:style = rect.get_attribute("style")rect_id = rect.get_attribute("id")if style and pattern_grey.search(style) and rect_id and first_grey_id == "null":first_grey_id = rect_idif style and pattern_red.search(style) and rect_id:match_red_ids.append(rect_id)# 进入第一个灰色方格,和它之前12个格子的颜色判断。if first_grey_id != "null":red_id_count_just_before_grey = 0grey_id_num = first_grey_id.split("_")grey_id_father = int(grey_id_num[1])grey_id_son = int(grey_id_num[2])for i in range [1:12]:possible_red_id = "null"k = grey_id_son - iif k >= 0:possible_red_id = "id_" + str(grey_id_father) + "_" + str(k)elif k < 0 and grey_id_father > 0:possible_red_id = "id_" + str(grey_id_father - 1) + "_" + str(k+34)  #目前那个svg的小格子群图像,一共有33排。else:continueif possbile_red_id != "null" and possible_red_id in match_red_ids:red_id_count_just_before_grey = red_id_count_just_before_grey + 1if red_id_count_just_before_grey > 7:signal_mail = Trueelse:passreturn signal_mailexcept Exception as e:send_email(subject="破访问失败了",content="你这程序写的不行",)return []finally:if 'driver' in locals():driver.quit()  # 确保资源释放if __name__ == "__main__":#print("🔥 启动Geckodriver动态解析...")#start_time = time.time()signal_sending = fetch_dynamic_rect_ids_with_gecko()if signal_sending:# 写个邮件发送程序,纯文本即可。send_email(subject="xx出现了8个红点",content="xx出现了8个红点",)#print(f"\n✅ 发现 {len(result_ids)} 个匹配元素:")#for idx, rect_id in enumerate(result_ids[:10], 1):#    print(f"{idx}. {rect_id}")#if len(result_ids) > 10:#    print(f"(仅显示前10条,共{len(result_ids)}条)")#print(f"\n⏱️ 总耗时: {time.time()-start_time:.2f}秒")

http://www.xdnf.cn/news/15469.html

相关文章:

  • 视频孪生与三维融合:智汇云舟赋能智慧化电力转型的破局之道
  • 【数据结构初阶】--单链表(二)
  • Flask服务器公外网访问,IPv6(亲测有效!!!!)
  • 哈希扩展 --- 海量数据处理
  • 20250714让荣品RD-RK3588开发板在Android13下长按关机
  • 【Linux】Jenkins Lts 配置构建 Maven 项目
  • 机床自动化中的“方言翻译官”:EtherNet/IP 转 PROFIBUS DP 实战手记
  • 3分钟搭建自动签到打卡RPA程序:验证码自动识别
  • 知识蒸馏:模型压缩与知识迁移的核心引擎
  • C++--unordered_set和unordered_map的使用
  • CCF-GESP 等级考试 2025年6月认证Python三级真题解析
  • EVOLVEpro安装使用教程-蛋白质语言模型驱动的快速定向进化
  • 2025年渗透测试面试题总结-2025年HW(护网面试) 45(题目+回答)
  • [Dify]-基础入门8- 使用 Dify 创建文档问答机器人(零代码实现)
  • openeuler使用桥接模式(包括新建虚拟机和已有虚拟机)
  • 【读书笔记】《C++ Software Design》第十章与第十一章 The Singleton Pattern The Last Guideline
  • 50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | ToastNotification(推送通知)
  • Android事件分发机制完整总结
  • 快速搭建Maven仓库服务
  • 深入理解 Linux 文件系统层级结构
  • 深入理解 Java JVM
  • Clojure和Golang中的Channel有什么异同(TBC)
  • AI驱动的软件工程(中):文档驱动的编码与执行
  • Python协程进阶:优雅终止与异常处理详解
  • python代码块的表示方法
  • 输入npm install后发生了什么
  • Maven 构建命令
  • HTML 基本骨架
  • 【LeetCode 热题 100】23. 合并 K 个升序链表——(解法一)逐一合并
  • DOS下EXE文件的分析 <1>