zoukankan      html  css  js  c++  java
  • 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:最后我想说的是,脚本调试中,不一定好用,没有调接口来的痛快,哎,屌丝的人生就是这样的,干什么都得靠抢。

  • 相关阅读:
    Android应用查看本地数据库
    C#导出和导入Excel模板功能
    数据库事务的四种隔离模式
    .NET进阶篇-丑话先说,Flag先立--致青春
    博客的第一天:回顾半年前的基础:SQL--基础查询+年月日格式+拼接
    【MySQL】你以为设置了并行复制就降低延迟了?这个你绝对想不到!
    中秋的月亮
    细看国产数据库,从根上知道如何学习?
    开篇2019
    Mysql学习笔记整理之数据库优化
  • 原文地址:https://www.cnblogs.com/medivhxu/p/6856719.html
Copyright © 2011-2022 走看看