实现追磨铁上小说功能,追磨铁小说,最近一直在磨铁上追书,可


最近一直在磨铁上追书,可是受不了天天刷新网页,网上抄了几段代码,实现了简单的追书功能,原理很简单,抓取章节网页,正则匹配章节信息,发送到设置好的邮箱,为方便识别,邮件题目是最新的章节。

未来打算匹配最新章节再发送邮件,如果可以,实现抓取章节内容,不过此为收费网站,估计很难实现。

目前采用python3实现,希望未来部署在云服务器上例如GAE,不过貌似不支持python3,希望以后解决,或者降级使用

import urllib.requestimport reimport timeimport smtplibfrom 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#获取输入的帖子单页htmldef 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,'屌丝道士最新章节 '+topicurl,y):        print('发送成功')    else:        print('发送失败')    return topicurl#调用函数html2=getHtml2('http://www.motie.com/book/24336/chapter')topicurl=gettopic(html2)print('采集完成!')#该片段来自于http://byrx.net

评论关闭