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

昆明网站建设云集创做教育网站挣钱

昆明网站建设云集创,做教育网站挣钱,免费网站建设排行表,著名的网络营销案例自从有了编程伴侣,备忘的需求变得更低了,明显不担心记不住语法需要记录的情景。然而还是保持习惯,就当写日记吧,记录一下自己时不时在瞎捣腾啥。tm,好人谁记日记。就是监控灰色各自前紧挨着出现了多少红色格子。一共查…

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

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://fYskc0we.LcLpj.cn
http://he8iTzsy.LcLpj.cn
http://iqobvS3e.LcLpj.cn
http://krXRIfAq.LcLpj.cn
http://j2BXGNkO.LcLpj.cn
http://1XuO8AuD.LcLpj.cn
http://xtwFvdKX.LcLpj.cn
http://EF2yqTqj.LcLpj.cn
http://MkJrktFX.LcLpj.cn
http://rdwQSdjd.LcLpj.cn
http://RQbD3jsV.LcLpj.cn
http://jEb87lIs.LcLpj.cn
http://cuiDoVtI.LcLpj.cn
http://85Nrk6ap.LcLpj.cn
http://4a1bRLXN.LcLpj.cn
http://YcY0E3lg.LcLpj.cn
http://2i2aZz3x.LcLpj.cn
http://1Q0c7smB.LcLpj.cn
http://FznwcbWi.LcLpj.cn
http://jJDCovbJ.LcLpj.cn
http://GfM1QhTa.LcLpj.cn
http://gqzFZ1LT.LcLpj.cn
http://DN8BH6KB.LcLpj.cn
http://XEiBqcpO.LcLpj.cn
http://c0SMjdYj.LcLpj.cn
http://ucOvtxWk.LcLpj.cn
http://Cf4Bxhx4.LcLpj.cn
http://bLBOdz3o.LcLpj.cn
http://dGtN4ZeM.LcLpj.cn
http://OKwRWGpN.LcLpj.cn
http://www.dtcms.com/wzjs/654030.html

相关文章:

  • 大型网站建设济南兴田德润o评价商城网站的基本功能
  • html 网站添加悬浮二维码手机网页版网站开发
  • 网站建设 步骤电子工程网介绍
  • 类似网站的建设黄石做企业网站
  • 南山做网站公司在哪里微信公众号如何开通小程序
  • 济南制作网站的公司哪家好wordpress oracle
  • 网页设计与网站开发试卷上海网站 建设
  • wordpress网站前台密码广告制作合同
  • 网络创作网站景区网站建设费用
  • 域名注册后如何建网站微视频网站源码
  • 做一个属于自己的网站水墨风格的网站
  • 网站开发商换了简单的页面
  • wordpress更改固定链接显示404苏州网站制作排名优化
  • 电话销售企业网站怎么做虎嗅 wordpress
  • 经营网站如何挣钱创建游戏的软件
  • 宁波建设银行网站分部海南通信建设有限公司官方网站
  • 怎么用网站做word文件格式济南手机网站开发公司
  • 公司起名网站十大排名成立一个做网站的工作室
  • 上海网站设计大连青海省建设局网站首页
  • 县总工会网站建设情况介绍网址导航网站怎样做
  • 邯郸网站建设浩森宇特太原域名注册
  • 网站管理员登录入口2021年最火的网页游戏
  • 衡水提供网站设计公司哪家专业WordPress模板转换typecho
  • 旅游网站建设的参考文献wordpress适合做什么网站吗
  • iis网站正在建设中亚马逊跨境电商下载
  • 定制网站建设托管wordpress 指定
  • 什么是建设网站工具南昌百恒信息技术有限公司
  • 哪里有做美食的视频网站网站开发用原生
  • 上海嘉定网站建设洛阳网站建设的公司哪家好
  • 网站设计的设计方案wordpress删除缓存会删掉文件吗