婆罗门
精华
|
战斗力 鹅
|
回帖 0
注册时间 2011-8-7
|
本帖最后由 treexper 于 2017-3-6 20:18 编辑
发个官网的自动监控机,有了发邮件通知你。
首先pip3 install bs4
然后- # coding=utf-8
- import time
- import urllib.request as request
- from bs4 import BeautifulSoup
- import smtplib
- from email.mime.text import MIMEText
- check_1 = False
- check_2 = False
- url = 'https://store.nintendo.co.jp/category/NINTENDOSWITCH/HAC_S_KAYAA.html'
- while True:
- ns_page = request.urlopen(url).read()
- soup = BeautifulSoup(ns_page, "html.parser")
- for p in soup.find_all('p', attrs={'class': 'zaiko'}):
- for span in p.find_all('span'):
- if str.strip(span.text) == '在庫×':
- check_1 = True
- break
- for p in soup.find_all('p', attrs={'class': 'nosale'}):
- if str.strip(p.text) == 'SOLD OUT':
- check_2 = True
- break
- if check_1 and check_2:
- print('sold out')
- else:
- msg = MIMEText(url, _subtype='plain', _charset='utf-8')
- msg['Subject'] = 'ゲットだぜ'
- msg['From'] = '<name>@163.com'
- msg['To'] = '<name>@163.com'
- server = smtplib.SMTP()
- server.connect('smtp.163.com')
- server.login('<name>', '<pass>')
- server.sendmail(msg['From'], msg['To'], msg.as_string())
- server.close()
- print('ゲットだぜ')
- break
- time.sleep(60)
复制代码 |
|