python实现淘宝秒杀聚划算抢购自动提醒源码


Posted in Python onJune 23, 2020

说明

本实例能够监控聚划算的抢购按钮,在聚划算整点聚的时间到达时发出提醒(音频文件自己定义位置)并自动弹开页面(URL自己定义)。

同时还可以通过命令行参数自定义刷新间隔时间(默认0.1s)和监控持续时间(默认1800s)。

源码

# encoding: utf-8 
''''' 
@author: Techzero 
@email: techzero@163.com 
@time: 2014-5-18 下午5:06:29 
''' 
import cStringIO 
import getopt 
import time 
import urllib2 
import subprocess 
import sys 
 
from datetime import datetime 
 
MEDIA_PLAYER = 'C:/Program Files/Windows Media Player/wmplayer.exe' 
MEDIA_FILE = 'D:/notify.mp3' 
CHROME = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe' 
URL = 'http://detail.ju.taobao.com/home.htm?spm=608.2214381.2.1.SY0wVT&item_id=16761325430&id=10000002801432' 
NO_X11 = False 
 
def get_current_button(): 
 '''''获取当前按钮状态''' 
 content = urllib2.urlopen(URL).read() #获取页面内容 
  
 buf = cStringIO.StringIO(content.decode('gbk').encode('utf8')) #将页面内容转换为输入流 
 current_button = None 
 for line in buf: 
  line = line.strip(' \n\r') #去掉回车换行 
   
  if line.find(r'<a href="#" rel="external nofollow" class="extra notice J_BuyButtonSub">开团提醒</a>') != -1: 
   current_button = '开团提醒' 
   break 
  elif line.find(r'<div class="main-box chance ">') != -1: 
   current_button = '还有机会' 
   break 
  elif line.find(r'<span class="out floatright">卖光了...</span>') != -1: 
   current_button = '卖光了' 
   break 
  elif line.find(r'<span class="out floatright">已结束...</span>') != -1: 
   current_button = '已结束' 
   break 
  elif line.find(r'<input type="submit" class="buyaction J_BuySubmit" title="马上抢" value="马上抢"/>') != -1: 
   current_button = '马上抢' 
   break 
   
 buf.close() 
 return current_button 
 
 
def notify(): 
 '''''发出通知并用Chrome打开秒杀页面''' 
 subprocess.Popen([MEDIA_PLAYER, MEDIA_FILE]) 
 if not NO_X11: 
  subprocess.Popen([CHROME, URL]) 
  print '打开页面' 
 
 
def monitor_button(interval, last): 
 '''''开始监视按钮''' 
 elapse = 0 
 while elapse < last: 
  current_button = get_current_button() 
 
  now = datetime.now() 
  print '%d-%d-%d %d:%d:%d - 现在按钮是 %s' % (now.year, now.month, now.day, now.hour, now.minute, now.second, current_button) 
 
  if current_button == '马上抢' or current_button == '还有机会': 
   print '赶紧抢购!' 
   notify() 
   break 
  elif current_button == '卖光了' or current_button == '已结束': 
   print '下次再试吧!' 
   break 
  else: 
   print '还没开始呢,再等等吧!' 
 
  time.sleep(interval) 
  elapse += interval 
 
 
def usage(): 
 print ''''' 
usage: monitor_mac_price.py [options] 
 
Options: 
 -i interval: 30 seconds by default. 
 -l last: 1800 seconds by default. 
 -h: Print this usage. 
 -X: Run under no X11. 
''' 
 
if __name__ == '__main__': 
 try: 
  opts, args = getopt.getopt(sys.argv[1:], 'i:l:hX') 
 except getopt.GetoptError, err: 
  print str(err) 
  sys.exit(1) 
 
 interval = 0.1 
 last = 1800 
 
 for opt, val in opts: 
  if opt == '-i': 
   interval = int(val) 
  elif opt == '-l': 
   last = int(val) 
  elif opt == '-X': 
   NO_X11 = True 
  elif opt == '-h': 
   usage() 
   sys.exit() 
 
 monitor_button(interval, last)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
linux下安装easy_install的方法
Feb 10 Python
Python实现的数据结构与算法之队列详解
Apr 22 Python
bat和python批量重命名文件的实现代码
May 19 Python
Python实现的rsa加密算法详解
Jan 24 Python
python针对excel的操作技巧
Mar 13 Python
python正则表达式之对号入座篇
Jul 24 Python
详解Python用三种方式统计词频的方法
Jul 29 Python
深入了解Python在HDA中的应用
Sep 05 Python
jupyter notebook中新建cell的方法与快捷键操作
Apr 22 Python
Tensorflow中的图(tf.Graph)和会话(tf.Session)的实现
Apr 22 Python
Python logging模块异步线程写日志实现过程解析
Jun 30 Python
OpenCV利用python来实现图像的直方图均衡化
Oct 21 Python
初探TensorFLow从文件读取图片的四种方式
Feb 06 #Python
用十张图详解TensorFlow数据读取机制(附代码)
Feb 06 #Python
Python实现matplotlib显示中文的方法详解
Feb 06 #Python
Python实现自动上京东抢手机
Feb 06 #Python
Python获取指定文件夹下的文件名的方法
Feb 06 #Python
TensorFlow如何实现反向传播
Feb 06 #Python
tensorflow TFRecords文件的生成和读取的方法
Feb 06 #Python
You might like
不用数据库的多用户文件自由上传投票系统(3)
2006/10/09 PHP
PHP 编写的 25个游戏脚本
2009/05/11 PHP
Yii2下session跨域名共存的解决方案
2017/02/04 PHP
php设计模式之装饰模式应用案例详解
2019/06/17 PHP
php如何把表单内容提交到数据库
2019/07/08 PHP
JavaScript判断textarea值是否为空并给出相应提示
2014/09/04 Javascript
js实现简单的碰壁反弹效果
2016/08/30 Javascript
Bootstrap路径导航与分页学习使用
2017/02/08 Javascript
angularJS深拷贝详解
2017/03/23 Javascript
深入nodejs中流(stream)的理解
2017/03/27 NodeJs
从零开始学习Node.js系列教程四:多页面实现的数学运算示例
2017/04/13 Javascript
Angular2学习教程之ng中变更检测问题详解
2017/05/28 Javascript
Vue+Jwt+SpringBoot+Ldap完成登录认证的示例代码
2018/05/21 Javascript
JavaScript遍历数组的三种方法map、forEach与filter实例详解
2019/02/27 Javascript
Jquery 动态添加元素并添加点击事件实现过程解析
2019/10/12 jQuery
Python 抓取动态网页内容方案详解
2014/12/25 Python
Python获取linux主机ip的简单实现方法
2016/04/18 Python
使用Python3 编写简单信用卡管理程序
2016/12/21 Python
python用户管理系统的实例讲解
2017/12/23 Python
Python画柱状统计图操作示例【基于matplotlib库】
2018/07/04 Python
对python中类的继承与方法重写介绍
2019/01/20 Python
Python中BeautifulSoup通过查找Id获取元素信息
2020/12/07 Python
Html5应用程序缓存(Cache manifest)
2018/06/04 HTML / CSS
英国第一摩托车和摩托车越野配件商店:GhostBikes
2019/03/10 全球购物
德国Discount-Apotheke中文官网:DC德式康线上药房
2020/02/18 全球购物
大学生创业计划书的格式要求
2013/12/29 职场文书
最新大学职业规划书范文
2013/12/30 职场文书
初中语文教学反思
2014/02/02 职场文书
机械设计及其自动化求职推荐信
2014/02/17 职场文书
禁毒宣传标语
2014/06/19 职场文书
医生见习报告范文
2014/11/03 职场文书
春节慰问信范文
2015/02/15 职场文书
外贸采购员岗位职责
2015/04/03 职场文书
党员转正介绍人意见
2015/06/03 职场文书
pytorch加载预训练模型与自己模型不匹配的解决方案
2021/05/13 Python
Go 语言中 20 个占位符的整理
2021/10/16 Golang