python截图html并发送带图片的html邮件
2021/7/20 14:05:47
本文主要是介绍python截图html并发送带图片的html邮件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
截图html
通过seleniun的webdriver打开html文件并截图
1 import os 2 import shutil 3 from selenium import webdriver 4 import time 5 import random 6 7 try: 8 driver = webdriver.Chrome(r"E:\chromedriver.exe") ## 自己现在并放到指定目录,需要自己修改 9 picture_url = "https://www.baidu.com" 10 11 driver.get(picture_url) 12 driver.maximize_window() 13 14 print(dir(driver)) 15 16 time.sleep(1) 17 18 driver.get_screenshot_as_file('E:\\11.jpg') 19 print("%s:截图成功!!!" % picture_url) 20 driver.close() 21 except BaseException as msg: 22 print(msg)
发送带图片的html邮件
#!/usr/bin/env python # coding=utf-8 import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.image import MIMEImage msg_from = 'porsche_qa@126.com' # 发送方邮箱 passwd = 'SLZCOAJIPHFGJOWB' # 填入发送方邮箱的授权码 msg_to = 'binzichen@126.com' # 收件人邮箱 def send(): subject = "python邮件测试" # 主题 msg = MIMEMultipart('related') content = MIMEText('<html><body><div><img src="cid:imageid" alt="imageid" style="width: 1065px;height: 450px;"></div></body></html>', 'html', 'utf-8') # 正文 msg.attach(content) msg['Subject'] = subject msg['From'] = msg_from msg['To'] = msg_to file = open(r"new.png", "rb") img_data = file.read() file.close() img = MIMEImage(img_data) img.add_header('Content-ID', 'imageid') msg.attach(img) try: s = smtplib.SMTP_SSL("smtp.126.com", 465) # 邮件服务器及端口号 s.login(msg_from, passwd) s.sendmail(msg_from, msg_to, msg.as_string()) print('发送成功!') except Exception: print('发送失败!') finally: s.quit() if __name__ == '__main__': send()
这篇关于python截图html并发送带图片的html邮件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程