磨铁追书2.0版,实现邮件发送附带链接

import urllib.request
import re
import time
import smtplib
import calendar
import formatter
from datetime import date
from email.mime.text import MIMEText

#要发给谁,可以发给多个人
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 = MIMEText(content,'html','utf-8')
	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):
	reg3=r"第[^<]+<"
	createdate = r"createdate[^>]+>"
	
	linksList = re.findall('<a href="(.*?)" >第.*?</a>',html2)
	#for link in linksList:
	#	tt= ''
	#	tt = 'http://www.motie.com' + link
	#	print(tt)
	#
	#kk = len(linksList)
	
	#if kk > 0:
	#	for i in range(1,5):
	#		tt = 'http://www.motie.com' + linksList[kk-i]
	#		#print(tt)
	#print(kk)
	cdlist = re.findall(createdate,html2)
	topiclist3=re.findall(reg3,html2)
	

		
	l = len(cdlist)
	ll = cdlist[l-1]
	kk = len(ll)
	ll = ll[12:kk-2]
	#得到最新更新时间
	#print(ll)
	x = 0
	y = ''
	z = 0
	j = ''
	#读取章节列表
	#print(topiclist3)
	for topicurl in topiclist3:
		#替换一些很无聊的不识别字符以及标题中的没用符号
		topicurl = topicurl.replace('‘',"'")
		topicurl = topicurl.replace('’',"'")
		topicurl = topicurl.replace('·',"*")
		topicurl = topicurl.replace('—',"-")
		topicurl = topicurl.replace('<','')
		topicurl = topicurl.replace('。','')
		topicurl = topicurl.replace('、','')
		x+=1
		if (topicurl.find('卷')!=-1):
			z+=1
			j = j + topicurl + ','
			y = y + '\n\n' + topicurl + '\n\n'
		else:
			topicurl = topicurl.ljust(30)
			y = y + topicurl + 'http://www.motie.com' + linksList[x-z-1] + '\n'
			
	j = j[:len(j)-1] 
	#打印章节
	print(y)
	#print(j)
	print()
	print("章节数目: %d"%(x-z))
	print("分卷数目: %d"%z)
	print("最新章节: %s"%topicurl)
	print("更新时间: %s"%ll)
	print("今天日期: %s"%date.today())
	print()
	yy = ll[:10]
	
	#if send_mail(mailto_list,'屌丝道士最新章节: '+topicurl+',更新时间:'+ll,y):
	#	print('发送成功')
	#else:
	#	print('发送失败')
	if yy==date.today():
		print("今天有更新")
		if send_mail(mailto_list,'屌丝道士最新章节: '+topicurl+',更新时间:'+ll,y):
			print('发送成功')
		else:
			print('发送失败')
	else:
		print("今天无更新")
		print("最新更新时间为:"+ll)
	
	return topicurl

#调用函数,读取小说章节目录
html2=getHtml2('http://www.motie.com/book/24336/chapter')
topicurl=gettopic(html2)
print('采集完成!')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值