本帖最后由 949825667@qq.co 于 2016-9-1 09:33 编辑
- import urllib.request
- import bs4
- import smtplib
- import email.mime.multipart
- import email.mime.text
- import time
- def douyu():
- url = "http://www.douyu.com/directory/game/DOTA2"
- web = urllib.request.urlopen(url)
- soup = bs4.BeautifulSoup(web, 'html.parser')
- home = soup.find(id='live-list-content')
- names = home.find_all(name='span', class_='dy-name ellipsis fl')
- ob=0
- for a in names:
- if a.string=='yyfyyf':
- print('胖头鱼直播了')
- ob = ob+1
- msg = email.mime.multipart.MIMEMultipart()
- msg['from'] = 'abc@qq.com'
- msg['to'] = 'target@qq.com'
- msg['subject'] = '直播提醒'
- content = '''
- 胖头鱼上线了,快看直播去!
- '''
- txt = email.mime.text.MIMEText(content)
- msg.attach(txt)
-
- smtp = smtplib
- smtp = smtplib.SMTP()
- smtp.connect('smtp.exmail.qq.com', '25')
- smtp.login('adc@qq.com', 'password')
- smtp.sendmail('abc@qq.com', 'target@qq.com', str(msg))
- smtp.quit()
- return ob
- def main():
- for i in range(288):
- if douyu()==1:
- time.sleep(43200)#如果发现在直播程序就暂停12小时
- douyu()
- time.sleep(300)
- if __name__ == '__main__':
- main()
复制代码 这个是下午想看斗鱼直播的时候发现喜欢的主播没在线!就想着写了这么个脚本!
主播上线,邮件提醒我,发邮件是看的别人的模板!
我把扩展名改成了pyw,放进了开机启动的目录里面!开机就运行(主要这样没有运行窗口好看点)!无聊的产物! |