前段时间手机又摔了个角, 实在惨不忍睹, 急需换机, 放眼望去安卓一片巨屏手机实非我所愿, 只能选5se, 秉承坚决不浪费的原则, 还是准备去数字尾巴淘个好成色的二手, 然而好成色又好价的机子总是被别人秒, 略蛋疼, 所以就整了这么个脚本, 刷到se字样的卖机贴就给我发邮件提醒

# !/usr/bin/python
# -*- coding: UTF-8 -*-
import re

import requests
import smtplib
from email.mime.text import MIMEText


def check():
    url = "http://trade.dgtle.com/dgtle_module.php?mod=trade&typeid=109"
    req = requests.get(url)
    text = req.text
    pattern = re.compile('class="tradetitle" title=".*"')
    lst = [i.split("title=")[-1].strip('"').lower().split('"')[0] for i in re.findall(pattern, text)]
    p = re.compile('se|6s|6sp')
    for i in lst:
        if re.search(p, i):
            send_mail(i, url)
            break


def send_mail(title, content):
    mail_host = "smtp.163.com"  # 设置服务器
    mail_user = ""  # 用户名
    mail_pass = ""  # 密码
    sender = '[email protected]'
    receivers = ['[email protected]']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

    message = MIMEText(content, 'plain', 'utf-8')
    message['From'] = "{}".format(sender)
    message['To'] = ",".join(receivers)
    message['Subject'] = title

    try:
        smtpObj = smtplib.SMTP_SSL(mail_host, 465)
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
        print("mail has been send successfully.")
    except smtplib.SMTPException as e:
        print(e)

if __name__ == "__main__":
    check()

效果如图(5se不好匹配, 就取了6s做关键字, 权当演示):

比较悲剧的是秒到一个玫瑰金的5se, 咳咳, 不套全黑壳简直不敢掏出来~太娘了