小米手机的确太难抢了,所以试着写了个程序玩下,还不知道行不行,明天试试!不过,还是要增加多个帐号一起抢,概率还是要大些,黄牛就是使用多帐号抢的!先附上源代码,有什么不对地方,大家帮忙指正!
#!/usr/bin/env python
# _*_ coding:utf-8 _*_import time
import os
from selenium import webdriverclass SubscribeTel(object):def __init__(self, username, passwd):self.username = usernameself.passwd = passwdself.login_url = 'https://account.xiaomi.com/pass/serviceLogin' # 小米登录网址self.login_sec = 'https://account.xiaomi.com/pass/auth/security/home' # 小米登录成功后网址self.sub_url = 'https://item.mi.com/product/10000085.html' # 小米min 2s 网址# 浏览器名称self.driver_name = 'firefox' # chrome firefox# 火狐浏览器第三方驱动self.executable_path = os.getcwd()+'/geckodriver' # 获取工程目录下的火狐驱动 chromedriverdef login(self):# 访问登录网址self.browser.get(self.login_url)# 填充用户名self.browser.find_element_by_name('user').send_keys(self.username)time.sleep(0.3)# 填充密码self.browser.find_element_by_name('password').send_keys(self.passwd)# 登录self.browser.find_element_by_id('login-button').click()# 循环等待登录,登录成功,跳出循环while True:if self.browser.current_url[:50] != self.login_sec:time.sleep(1)else:# logbticket.info("登陆成功...")print('登录成功...')breakdef start_sub(self):# 创建一个浏览器对象self.browser = webdriver.Firefox()# 设置窗口大小尺寸self.browser.set_window_size(1400, 1000)# 用户登录self.login()# 进入预购页面self.browser.get(self.sub_url)self.browser.implicitly_wait(2)if self.browser.find_element_by_xpath("//a[@data-name='立即预约']"):self.browser.find_element_by_xpath("//a[@data-name='立即预约']").click()# 选择内存self.browser.find_element_by_xpath("//li[@data-name='6GB+128GB']").click()# 选择颜色self.browser.find_element_by_xpath("//img[@alt='白色']").click()while True:times = self.browser.find_element_by_xpath("//span[@class='time J_orderTime']").textif times == u'剩 00 时 00 分 00 秒':self.browser.find_element_by_xpath("//a[@data-name='加入购物车']").click()print('加入购物车成功...')breakelse:time.sleep(0.5)if __name__ == '__main__':username = 'xxxxxxxxx'passwd = 'xxxxxxx'Tel = SubscribeTel(username, passwd)Tel.start_sub()