- 每分钟抓取一次课程页面学习人数.
- 和前次进行对比, 数量增加意味课程卖出, 播放本地音乐.
- 同时监听多们课程.
from threading import Timer
from scrapy.selector import Selector
from subprocess import getoutput
import requests
COURSES = {
# Python高级编程技巧实战
62: {
'url': 'http://coding.imooc.com/class/62.html',
'mp3': 'happy.mp3',
},
75: {
'url': 'http://coding.imooc.com/class/75.html',
'mp3': 'happy2.mp3',
},
74: {
'url': 'http://coding.imooc.com/class/74.html',
'mp3': 'happy3.mp3',
},
}
def getSalesVolume(courses):
res = {}
for course in courses:
url = COURSES[course]['url']
response = requests.get(url)
sel = Selector(text=response.text)
sv = sel.css('div.static-item:nth-child(3) > \
span.meta-value > strong::text').extract_first()
res[course] = int(sv)
return res
def loop(courses, svOld):
try:
sv = getSalesVolume(courses)
for course in courses:
print(course, svOld[course], sv[course])
cmd = 'play %s' % COURSES[course]['mp3']
for _ in range(sv[course] - svOld[course]):
getoutput(cmd)
svOld = sv
except IOError as e:
print(e)
Timer(60, loop, args=(courses, svOld)).start()
courses = [62, 75, 74]
loop(courses, getSalesVolume(courses))
点击查看更多内容
9人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦