python抢小米6自动化脚本


 1 #!/bin/env python
 2 # coding=utf-8
 3 
 4 from selenium import webdriver
 5 import time 6 import unittest 7 8 9 class GetXiaoMi: 10 driver = webdriver.Chrome() 11 url = 'https://item.mi.com/product/10000041.html' 12 13 def login(self): 14 # try: 15  self.driver.get(self.url) 16 home_login_butten = self.driver.find_element_by_xpath(".//*[@id='J_buyBox']/div/div[1]/div/a[1]") 17  home_login_butten.click() 18 input_username = self.driver.find_element_by_class_name('item_account') 19  input_username.clear() 20 input_username.send_keys('username') 21 input_password = self.driver.find_element_by_id('pwd') 22  input_password.clear() 23 input_password.send_keys('password') 24 login_butten = self.driver.find_element_by_id('login-button') 25  login_butten.click() 26 self.driver.assertIsNotNone(self.driver.find_element_by_xpath(".//*[@id='error-outcon']/div/span]"), 27 u"登陆失败,请检查用户名或密码") 28 # except Exception, e: 29 # print e 30 31  @staticmethod 32 def get_sys_time(): 33 sys_time = time.time() 34 return sys_time 35 36  @staticmethod 37 def set_stamp(): 38 set_time = '2017-05-12 09:59:55' # 设置抢购时间,最好提前几秒 39 # 将其转换为时间数组 40 time_array = time.strptime(set_time, '%Y-%m-%d %H:%M:%S') 41 # 转换为时间戳 42 time_stamp = int(time.mktime(time_array)) 43 return time_stamp 44 45 def get_xiaomi(self): 46 try: 47 if self.get_sys_time() >= self.set_stamp(): 48 while True: 49 self.driver.find_element_by_class_name('btn btn-primary btn-biglarge J_proBuyBtn add').click() 50 if self.assertTrue(u'你来晚了', driver.title): 51 print u'又悲剧了,默默的问候小米~' 52 break 53 else: 54 print u'<-------------赶紧手动付款吧------------>' 55 else: 56 print u'时间设置错误' 57 except Exception, e: 58 print e 59 60 61 if __name__ == '__main__': 62 run = GetXiaoMi() 63 run.get_xiaomi()

 

 

 

 

代码报错?你是否安装了selenium模块?请自行百度~

PS:最后我想说的是,脚本调试中,不一定好用,没有调接口来的痛快,哎,屌丝的人生就是这样的,干什么都得靠抢。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM