-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
68 lines (58 loc) · 2.19 KB
/
web.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
from selenium import webdriver
import time
from PIL import Image
im = Image.open("请勿删除此文件")
im.show()
options = webdriver.ChromeOptions()
options.add_argument("disable-infobars")
browser = webdriver.Chrome(chrome_options=options)
browser.get("http://zhihuishu.com")
print("====欢迎使用智慧树辅助程序====")
r = input("\n登陆您的账号,打开课程播放页面并开始播放后,关闭其他所有网页,点此窗口按回车后程序开始运行")
windows = browser.window_handles
browser.switch_to_window(windows[-1])
print("\n智慧树辅助程序开始运行")
# 切换到最新打开的页面
# 进入下一课
def click_next():
browser.execute_script('document.getElementsByClassName("controlsBar")[0].style.display="block";')
time.sleep(2)
nextButton = browser.find_element_by_xpath('//div[@id="nextBtn"]')
nextButton.click()
def check_end():
playBtn = browser.find_element_by_id("playButton")
if "playButton" in playBtn.get_attribute("class"):
return True
def close_tanti():
try:
ele = browser.find_element_by_id('tmDialog_iframe')
if ele:
print(time.strftime("[%H:%M] ")+'检测到弹题')
browser.switch_to_frame(ele)
time.sleep(2)
divs = browser.find_elements_by_xpath('//div[@class="answerOption"]/label/input')
divs[1].click()
print(time.strftime("[%H:%M] ")+'已点击第二个答案')
browser.switch_to_default_content()
nextButton = browser.find_element_by_xpath('//a[@class="popbtn_cancel"]')
time.sleep(2)
nextButton.click()
return True
else:
return False
except Exception as e:
print(e)
return False
if __name__ == '__main__':
while True:
try:
if check_end():
if close_tanti():
print(time.strftime("[%H:%M] ")+"已自动关闭弹题")
continue
click_next()
print(time.strftime("[%H:%M] ")+"已自动进入下一集")
print("======辅助程序持续运行中======")
except:
time.sleep(5)
time.sleep(5)