日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python生成html邮件

發布時間:2025/5/22 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python生成html邮件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近在學習Python,這是我第一個Python腳本。沒有技術含量,之前不知道zip()函數,想讓2個結果對應起來,弄了好久,后來問了做php的同事,才知道。

需求:實現爬蟲每次下載完成后生成html統計郵件,發送到郵箱;

#!/usr/bin/env python #coding:utf8 import os td = """ <td style="border-style:inset;border-color:#808080;padding:0px;border-width:1px">""" num = 1 os.system("ls -lth /data0/backup/video/* |awk '{print $1\" \"$3\" \"$NF\" \"$6}'> /tmp/fileinfo.log") os.system("ls -lth /data0/backup/video/* |awk '{print $5}' > /tmp/filesize.txt") maketime=os.popen('date +%Y-%m-%d" "%H":"%M').read() number=os.popen('ls /data0/backup/video/|wc -l').read() print """ <div><span style="line-height: 1.5;">備份時間:%s&nbsp;</span></div> <div><span style="line-height: 1.5;">總文件數:%s&nbsp;</span></div> <div><span style="line-height: 1.5;">文件列表:</span></div>"""%(maketime,number) print """<table border="1" cellspacing="0px" style="text-align: center; border: 1px outset rgb(128, 128, 128); border-collapse: collapse; width: 60%; border-spacing: 0px;"> <tbody>""" file=open('/tmp/fileinfo.log') size=open('/tmp/filesize.txt') filename=zip(size,file) print " <th>編號</th>" #print " <th>用戶</th>" print " <th>時間</th>" print " <th>大小</th>" print " <th>文件</th>" for k,v in filename: info = v.split() s = k.split() print " <tr>" print "%s%s</td>"%(td,num) #print "%s%s</td>"%(td,info[1]) print "%s%s</td>"%(td,info[3]) print "%s%s</td>"%(td,s[0]) print "%s%s</td>"%(td,info[2]) print " </tr>" num = num+1 print """ </tbody> </table> <div style="text-align: center;"><span style="line-height: 1.7;"></span></div> """

?實現效果

?

附Linux下發送html郵件方式:

mail?-s?"$(echo?-e?"title\nContent-Type:?text/html")"?mail@qq.com

?

轉載于:https://blog.51cto.com/bbaobelief/1380479

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的Python生成html邮件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。