- import urllib.request
- import re
- import time
- import smtplib
- from email.mime.text import MIMEText
- #要发给谁,这里发给1个人
- mailto_list=["aaa@gmail.com",""]
- #####################
- #设置服务器,用户名、口令以及邮箱的后缀
- mail_host="smtp.163.com"
- mail_user="aaa"
- mail_pass="aaa"
- mail_postfix="163.com"
- ######################
- def send_mail(to_list,sub,content):
- #to_list:发给谁
- #sub:主题
- #content:内容
- #send_mail("aaa@126.com","sub","content")
- me = "aaa <aaa@163.com>"
- msg = MIMEText(content)
- msg['Subject'] = sub
- msg['From'] = me
- msg['To'] = ";".join(mailto_list)
- try:
- s = smtplib.SMTP()
- s.connect(mail_host)
- s.login(mail_user,mail_pass)
- s.sendmail(me, mailto_list, msg.as_string())
- s.close()
- return True
- except Exception as e:
- print(str(e))
- return False
- #获取输入的帖子单页html
- def getHtml2(url2):
- html2=urllib.request.urlopen(url2).read().decode('utf-8')
- return html2
- #抽取图片相关列表,并下载图片
- def gettopic(html2):
- reg2=r'第\\w+节\\s\\w*'
- topiclist=re.findall(reg2,html2)
- x=0
- y=''
- #print(topiclist)
- #限制下载的图片数
- for topicurl in topiclist:
- x+=1
- y=y+topicurl+'\\n'
- print(topicurl)
- print(x)
- if send_mail(mailto_list,'
- #该片段来自于http://www.codesnippet.cn/detail/121220137967.html
来源: http://www.codesnippet.cn/detail/121220137967.html