forked from wwwgang/getXM9
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetxiaomi9pro.py
54 lines (43 loc) · 1.71 KB
/
getxiaomi9pro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from selenium import webdriver
import time
class xiaomi():
lurl = 'https://account.xiaomi.com/'
burl = 'https://item.mi.com/product/9372.html'
atime = 1552960800
def __init__(self, usernme, pwd):
self.username = usernme
self.pwd = pwd
self.b = webdriver.Firefox(executable_path='geckodriver.exe')
def login(self):
print('正在登陆...\n')
self.b.get(self.lurl)
self.b.find_element_by_id('username').send_keys(self.username)
self.b.find_element_by_id('pwd').send_keys(self.pwd)
self.b.find_element_by_id('login-button').click()
def buy(self):
print('进入米9秒杀页面...\n')
self.b.get(self.burl)
print('正在选择型号配件...\n')
try:
self.b.find_element_by_xpath('//*[@id="J_buyBox"]/div/div[1]/div/a[1]').click()
self.b.find_element_by_xpath('//*[@id="J_agreeModal"]/div[3]/div/button[2]').click()
time.sleep(3)
self.b.find_element_by_xpath('//*[@id="J_buyBtnBox"]/li[1]').click()
except:
pass
while True:
if time.time() > self.atime:
try:
self.b.find_element_by_xpath('//*[@id="J_buyBtnBox"]/li[1]').click()
print('开始抢购...\n')
except:
print('异常,退出抢购')
break
else:
print('\n\n', '还未到达抢购时间\n', '当前时间是:', time.time(), '\n', '抢购时间是:', self.atime, '\n\n')
if __name__ == '__main__':
username = input('username:\n')
pwd = input('pwd:\n')
a = xiaomi(usernme=username, pwd=pwd)
a.login()
a.buy()