Python爬天气预报,再发到自己的邮箱
来源:互联网 发布:java简单聊天室程序 编辑:程序博客网 时间:2024/06/03 17:45
from email.mime.text import MIMETextfrom email.header import Headerfrom smtplib import SMTP_SSL####from urllib import requestimport re###url = 'http://www.weather.com.cn/weather1d/404155100.shtml'getRequest = request.urlopen(url)response = getRequest.read().decode("utf-8")file = open("2345Weather.txt", "w+") # wb -> write binaryfile.write(response)file.close()####regex = r'<input type="hidden" id="hidden_title" value="(.+)" />'pattern = re.compile(regex)text = re.findall(pattern, response)print(text)f=open("weather.txt","w+")f.writelines(text)f.close()text = str(text)[2:-2]#####qq邮箱smtp服务器host_server = 'smtp.qq.com'#sender_qq为发件人的qq号码sender_qq = 'xxx xxx xxx'#pwd为qq邮箱的授权码 16位pwd = 'xxx xxx xxx xxx xxxx'#发件人的邮箱sender_qq_mail = 'xxx xxx xxx@qq.com'#收件人邮箱receiver = 'xxx xxx xxx@qq.com'#邮件的正文内容mail_content = text#邮件标题mail_title = '里贾纳 天气预报'#ssl登录smtp = SMTP_SSL(host_server)#set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式smtp.set_debuglevel(1)smtp.ehlo(host_server)smtp.login(sender_qq, pwd)msg = MIMEText(mail_content, "plain", 'utf-8')msg["Subject"] = Header(mail_title, 'utf-8')msg["From"] = sender_qq_mailmsg["To"] = receiversmtp.sendmail(sender_qq_mail, receiver, msg.as_string())smtp.quit()
阅读全文
0 0
- Python爬天气预报,再发到自己的邮箱
- 【python 天气预报】python制作属于自己的天气预报
- Python创建自己的邮箱应用(1)
- Python创建自己的邮箱应用(2)
- python 的查询天气预报
- 保护自己的邮箱
- 实现自己的天气预报(源代码)
- Python发送天气预报信息到手机
- 利用Python发送天气预报信息到手机
- 使用python爬取网页发送到邮箱
- 精确到地区的天气预报
- 天气预报接口,在自己的网页上加入天气预报吧
- python 获取省份的天气预报
- 导入自己的邮箱联系人
- 搭建自己的域名邮箱
- 在自己的网站中插入天气预报
- 用webservice发布自己的天气预报服务
- 关于用python 的imaplib提取自己163,qq邮箱的内容
- [AHK]修改系统时间
- java集合基础
- 使用Charels对Android模拟器上的app进行抓包
- 获取文件夹中的文件名写入文件
- 算法面试100题——2.设计包含min函数的栈
- Python爬天气预报,再发到自己的邮箱
- Android学习笔记七之ContentProvider
- Retrofit2.0 公共参数(固定参数)
- 【权限设计】采用BigInteger进行的权限设计
- mongodb常用命令脚本化-自动化运维
- 分页
- Matplotlib 绘图教程(2D入门)
- Java获取客户端Ip
- VS2013+OBS开发