Contents
  1. 1. install
  2. 2. play

install

pip install selenium

https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/

play

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
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

# edge = webdriver.Edge()
# edge.get("https://www.baidu.com")


class Tester(object):

def __init__(self):
self.driver = webdriver.Chrome()
self.driver.get(
"https://dangjian.hxq.komect.com/hldjLogin/?activityId=1717&corpId=753063193924136960&homeUrl=http"
"://dangjian.hxq.komect.com/dkdtweb/")

def login(self, phone):
self.driver.find_element(By.CLASS_NAME, "input-user-phone").clear()
self.driver.find_element(By.CLASS_NAME, "input-user-phone").send_keys(phone)
self.driver.find_element(By.CLASS_NAME, "get-code").click()
code = input("输入验证码:")
self.driver.find_element(By.ID, "loginCode").clear()
self.driver.find_element(By.ID, "loginCode").send_keys(code)
self.driver.find_element(By.CLASS_NAME, "login-btn").click()

def play(self):
self.driver.find_element(By.CLASS_NAME, "btn-begin").click() # 开始
time.sleep(5)

for i in range(5):
try:
self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[11]/div[3]/div[3]/div/div')
hasc = True
except:
hasc = False

if hasc:
self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[11]/div[3]/div[3]/div/div').click()
else:
self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[11]/div[3]/div[1]/div/div').click()
time.sleep(5)

# self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[11]/div[3]/div[1]/div/div').click()
# self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[11]/div[3]/div[2]/div/div').click()
# self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[11]/div[3]/div[3]/div/div').click()
# self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[11]/div[3]/div[4]/div/div').click()

# self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[8]')

print(self.driver.find_element(By.CLASS_NAME, "result-got").text)
self.driver.find_element(By.CLASS_NAME, "btn-continue").click() # 继续挑战
time.sleep(3)

self.driver.get_cookies()

def start_game(self, n):
print("score: " + self.driver.find_element(By.CLASS_NAME, "value").text)
self.driver.find_element(By.CLASS_NAME, "with-computer").click()

for i in range(n):
print(i)
self.play()

def __del__(self):
self.driver.quit()


if __name__ == '__main__':
instance = Tester()
phone = "xx"
instance.login(phone)
instance.start_game(10)

pip install webdriver-manager