-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathHUAWEI STORE GO.py
383 lines (355 loc) · 15 KB
/
HUAWEI STORE GO.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# coding = utf-8
# HUAWEI STORE GO 项目Github地址:https://github.com/XYZliang/HUAWEI-STORE-GO
# 本python脚本仅供大家学习交流,严禁严禁用于商业用途,不得利用本项目进行任何形式的盈利活动,请在24小时内删除。
# 如果本项目对你有所帮助,麻烦项目给个星星鼓励一下哦
################################################################用户配置################################################################
# 账号密码
ACCOUNTS = {
"华为账户账号/电话/邮箱": "账户密码"
}
# chrome driver路径
chrome_driver = "/usr/local/bin/chromedriver" # Mac示例
# chrome_driver = "C:\Google\ChromeApplication\chromedriver.exe" # Windows示例
# 手机链接
BUY_URL = 'https://www.vmall.com/product/10086232069466.html'
# 开始自动刷新等待抢购按钮出现的时间点,建议提前10-30s,并提前2-5分钟启动python脚本,确保登陆成功,进入页面。
BEGIN_GO = '2021-02-23 10:07:50'
# 是否启动自动选手机参数。1为开启,0为关闭。当不启用时,无需填写下面的参数,此时抢购会默认网页上的默(第一个颜色、版本、套餐)。若不需要请关闭此选项能加快速度。
AUTO_SELECT = 1
# 是否启动自动选手机颜色
AUTO_COLOR = 1
# 是否启动自动选手机版本
AUTO_EDITION = 1
# 是否启动自动选手机套餐
AUTO_COMBO = 1
# 颜色,仅当AUTO_SELECT=1和AUTO_COLOR=1时才需要写
COLOR = '翡冷翠'
# 版本,仅当AUTO_SELECT=1和AUTO_EDITION=1时才需要写
EDITION = '5G全网通 8GB+256GB'
# 套餐,仅当AUTO_SELECT=1和AUTO_COMBO=1时才需要写
COMBO = '官方标配'
# 登陆信任 0表示不信任,1表示信任。一般无需改动。若信任,当您下次登录时,系统将不会要求您提供验证码。对于HUAWEI STORE普通版脚本,每次运行脚本即创建一个新Chrome,信任意义不大,默认为0,建议设置为0
TRUST = 0
################################################################程序开始################################################################
from selenium.webdriver.common.action_chains import ActionChains
import selenium
from threading import Thread
import time
from selenium import webdriver
# 登录url,一般无需改动
LOGIN_URL = 'https://hwid1.vmall.com/CAS/portal/login.html?validated=true&themeName=red&service=https%3A%2F%2Fwww.vmall.com%2Faccount%2Facaslogin%3Furl%3Dhttps%253A%252F%252Fwww.vmall.com%252F&loginChannel=26000000&reqClientType=26&lang=zh-cn'
# 进到购买页面后提交订单
def submitOrder(driver, user):
time.sleep(1)
if BUY_URL == driver.current_url:
print(user + ':当前页面还在商品详情!!!')
time.sleep(3)
goToBuy(driver, user)
else:
order_url = driver.current_url
while True:
try:
submitOrder = driver.find_element_by_link_text('提交订单')
submitOrder.click()
print(user + ':成功提交订单')
time.sleep(1)
break
except:
print(user + ':提交不了订单!!!!!!!!!!!!!!!!!!!!!快去自己提交!!')
time.sleep(1) # 到了订单提交页面提交不了订单一直等待
pass
print(user + "请自行查看提交结果!!程序60s后退出")
exit(60)
# 排队中
def onQueue(driver, user):
time.sleep(1)
nowUrl = driver.current_url
print(user + '开始排队:' + BEGIN_GO)
while True:
errorbutton = driver.find_element_by_id("boxCloseBtn")
if errorbutton.get_attribute('style') == 'display: none;':
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime())+user + "抢购失败,再试一次")
goToBuy(driver, user)
else:
if nowUrl != driver.current_url and driver.current_url != BUY_URL:
print(user + ':成功!排队页面跳转了!!!!!!!!!!!!!!')
submitOrder(driver, user)
else:
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime())+user + ':排队中')
time.sleep(0.2) # 排队中
# 选择手机规格
def select(driver, user):
if AUTO_COLOR == 1:
try:
color = driver.find_element_by_link_text(COLOR)
color.click()
print(user+COLOR + '选择成功!')
except:
time.sleep(1)
try:
color = driver.find_element_by_link_text(COLOR)
color.click()
print(user+COLOR + '选择成功!')
except:
print(user+'颜色选择错误!请手动选择!')
else:
print(user+'无需选择颜色')
if AUTO_EDITION == 1:
try:
edition = driver.find_element_by_link_text(EDITION)
edition.click()
print(user+EDITION + '选择成功!')
except:
time.sleep(1)
try:
edition = driver.find_element_by_link_text(EDITION)
edition.click()
print(user+EDITION + '选择成功!')
except:
print(user+'版本选择错误!请手动选择!')
else:
print(user+'无需选择版本')
if AUTO_COMBO == 1:
try:
combo = driver.find_element_by_link_text(COMBO)
combo.click()
print(user+COMBO + '选择成功!')
except:
time.sleep(1)
try:
combo = driver.find_element_by_link_text(COMBO)
combo.click()
print(user+COMBO + '选择成功!')
except:
print(user+'套餐选择错误!请手动选择!')
else:
print(user+'无需选择套餐')
# 登录成功去到购买页面
def goToBuy(driver, user):
autoSelect = AUTO_SELECT
driver.get(BUY_URL)
time.sleep(0.5)
if BUY_URL != driver.current_url:
driver.get(BUY_URL)
print(user + '打开购买页面')
time.sleep(0.5)
# 转换成抢购时间戳
timeArray = time.strptime(BEGIN_GO, "%Y-%m-%d %H:%M:%S")
timestamp = time.mktime(timeArray)
# 再次登陆
try:
denglu1 = driver.find_element_by_id("top-index-loginUrl")
denglu1.click()
time.sleep(0.5)
except:
print(user + '已经登陆')
# 结束标志位
over = False
time.sleep(0.5)
if(autoSelect == 1):
select(driver, user)
else:
print(user+'跳过选择配置')
isRemind = 0
while True:
if isRemind == 0:
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime()) + user + '准备完毕,开始等待')
isRemind = 1
if time.time() >= timestamp: # 到了抢购时间
text = driver.find_elements_by_xpath(
'//*[@id="pro-operation"]/a')[0].text
if text == '已售完':
over = True
break
elif text == '立即申购':
buyButton = driver.find_element_by_link_text('立即申购')
isRemindd = 0
try:
if buyButton.get_attribute('class') != 'product-button02 disabled':
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime()) + user + '可以开始申购,立即申购')
buyButton.click()
break
else:
try:
textnext = driver.find_elements_by_xpath(
'//div[@id="pro-operation-countdown"]/p')[0].text
if isRemind != 2 and isRemindd != 0:
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +
user + '准备开始下一轮' + textnext.replace('开售:', '') + '的抢购')
isRemindd = 1
except:
if isRemind != 2 and isRemindd != 0:
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime()) + user + '准备开始下一轮的抢购')
isRemindd = 1
except:
buyButton = driver.find_element_by_link_text('立即申购')
elif text == '0元预约':
buyButton = driver.find_element_by_link_text('0元预约')
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime()) + user + ':请手动进行预约。程序将在一分钟后退出')
buyButton.click()
exit(60)
elif text == '参与预约':
buyButton = driver.find_element_by_link_text('参与预约')
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime()) + user + ':请手动进行预约。程序将在一分钟后退出')
buyButton.click()
exit(60)
else:
over = True
break
elif time.time() < timestamp-15:
if isRemind == 1:
isRemind = 2
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +
user + '未到脚本开启时间,请选择好抢购的颜色、版本、套餐等(若已经配置则忽略),将在设定的脚本启动时间前15秒启动')
else:
print('-', end="")
time.sleep(0.99)
else:
if isRemind == 1 or isRemind == 2:
if isRemind == 2:
print("")
isRemind = 3
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime()) + user + '即将开始抢购,程序启动')
time.sleep(0.05)
if over:
print(user+"很遗憾,"+time.strftime("%H:%M:%S",
time.localtime())+"抢购结束,程序将在60s后退出")
time.sleep(60)
driver.quit()
exit()
else:
onQueue(driver, user)
# 信任浏览器(driver)
def trustdriver(driver, user):
try:
if TRUST == 0:
try:
trust = driver.find_element_by_xpath(
'//div[@ht="click_dialog_leftbtn"]')
trust.click()
except:
print(user+'不信任出错,请自行点击不信任')
if TRUST == 1:
try:
trust = driver.find_element_by_xpath(
'//div[@ht="click_dialog_rightbtn"]')
trust.click()
except:
print(user + '信任出错,请自行点击信任')
except:
return
# 发送验证码
def sendcode(driver, user):
try:
isGetVerification = driver.find_element_by_xpath(
'//div[@ht="click_authentication_getAuthcode"]')
number = driver.find_element_by_xpath('//div[@id="accountDiv"]')
except:
time.sleep(0.2)
if isGetVerification.text == '获取验证码':
isGetVerification.click()
if number is None:
print(user + '验证码已经发送')
else:
print(user+'验证码已经发送至'+number.text)
try:
inputdiv = driver.find_element_by_xpath(
'//input[@ht="input_authentication_authcode"]')
inputdiv.click()
# 自动点击输入框
except:
time.sleep(0.1)
time.sleep(0.1)
# 登录商城,登陆成功后至商城首页然后跳转至抢购页面
def loginMall(user, pwd):
driver = webdriver.Chrome(executable_path=chrome_driver)
driver.get(LOGIN_URL)
try:
time.sleep(3) # 等待页面加载完成
account = driver.find_element_by_xpath(
'//input[@ht="input_pwdlogin_account"]')
account.send_keys(user)
password = driver.find_element_by_xpath(
'//input[@ht="input_pwdlogin_pwd"]')
password.send_keys(pwd)
denglu = driver.find_element_by_xpath(
'//div[@ht="click_pwdlogin_submitLogin"]')
ActionChains(driver).move_to_element(denglu).perform()
time.sleep(1)
denglu.click()
print(user + '成功输入了账号密码,尝试登陆.')
except:
print(user + '账号密码不能输入,请手动输入并登陆!')
isRemind = 0
islogin = 0
while True:
time.sleep(0.5)
if "登录" not in driver.title: # 页面跳转登陆成功
print(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime()) + user + '登录成功!!')
goToBuy(driver, user)
break
else: # 没有登陆成功
if isRemind == 0:
print(user + '请手动完成认证并登陆!')
isRemind = 1
try: # 判断是否在获取验证码界面
isGetVerification = driver.find_element_by_xpath(
'//div[@class="hwid-dialog-header paddingBottom18"]/div')
if isGetVerification.text == '身份验证':
sendcode(driver, user)
islogin = 1
except:
try:
denglu = driver.find_element_by_link_text('登陆')
denglu.click()
print(denglu)
except:
time.sleep(0.05)
if islogin == 1:
try: # 判断是否在信任浏览器界面
isGetVerification = driver.find_element_by_xpath(
'//div[@class="hwid-dialog-header paddingBottom40"]/div')
if '是否信任此浏览器' in isGetVerification.text:
islogin = 2
trustdriver(driver, user)
except:
time.sleep(0.05)
if islogin == 0 or islogin == 1:
error = ""
try:
error = driver.find_element_by_xpath(
'//div[@class="marginTB8 hwid-input-msg-error"]').text
print(error)
except:
time.sleep(0.1)
if '图形验证码' in error:
try:
denglu.click()
except:
time.sleep(0.1)
elif '较为频繁' in error:
print('验证码获取频繁,请一小时后再试,或者使用HUAWEI STORE GO DEV版信任浏览器')
print('60s后程序退出')
time.sleep(60)
exit()
if __name__ == "__main__":
# 账号密码
data = ACCOUNTS
# 构建线程
threads = []
for account, pwd in data.items():
t = Thread(target=loginMall, args=(account, pwd,))
threads.append(t)
# 启动所有线程
for thr in threads:
time.sleep(1)
thr.start()