wangzhenxing
创建存放url的文档info_url,检测url并将返回值和url写入新文件info_sta


import requests

def url():
    with open(\'info_url\') as f:
        with open(\'info_sta\',\'w\') as f1:
            st = \'\'
            for line in f:
                line = line.strip()
                sta = str(requests.get(line).status_code)
                st = line+\'|\'+sta
                f1.write(st+\'\n\')

    with open(\'info_sta\') as f:
        st = \'\'
        for line in f:
            url,status = line.strip().split(\'|\')
            if status != \'404\':
                st = st + url + \'\n\'
    return st
主程序


import sys
import os
from email.mime.text import MIMEText
import smtplib
from email.header import Header
sys.path.insert(0,os.path.dirname(os.getcwd()))
import check_status

url = check_status.url()

mail_host = \'smtp.ym.163.com\'  #smtp
mail_user = \'baojing@zenking.cc\'
mail_pass = \'chanjing\'

receivers = [\'wzxing21@sina.com\',\'1506353195@qq.com\']

#第一部分是文本内容,第二部分plain设置文本格式,第三部分是编码设置
message = MIMEText(\'URL检测失败 :\n%s\'%url,\'plain\',\'utf-8\')
message[\'From\'] = mail_user
message[\'To\'] = Header(\'wzxing21@sina.com,1506353195@qq.com\')

subject = \'邮件告警\'    #主题
message[\'subject\'] = Header(subject,\'utf-8\')

smtpobj = smtplib.SMTP(\'smtp.ym.163.com\')
smtpobj.login(mail_user,mail_pass)
smtpobj.sendmail(mail_user,receivers,message.as_string())
print(\'发送成功\')

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2021-10-05
  • 2021-04-07
  • 2022-02-23
猜你喜欢
  • 2022-12-23
  • 2021-07-06
  • 2021-11-17
  • 2021-11-20
  • 2021-10-30
  • 2022-12-23
相关资源
相似解决方案