-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
83 lines (63 loc) · 2.38 KB
/
main.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
from selenium import webdriver
def translate(choose): #把ABCD转化成为0123
if choose == 'A' or choose == 'a':
return 0
elif choose == 'B' or choose == 'b':
return 1
elif choose == 'C' or choose == 'c':
return 2
elif choose == 'D' or choose == 'd':
return 3
elif choose == 'E' or choose == 'e':
return 4
elif choose == 'F' or choose == 'f':
return 5
elif choose == 'G' or choose == 'g':
return 6
else:
pass
def submit_choice(question_number, choose): #选择题
answer = questions[question_number].find_elements_by_css_selector('li')
answer[translate(choose)].click()
def submit_multi_choice(question_number, choose_list): #多选题
pass
answer = questions[question_number].find_elements_by_css_selector('li')
for i in range(len(choose_list)):
answer[translate(choose_list[i])].click()
def submit_text(question_number, text): #填空题
text_area = questions[question_number].find_element_by_css_selector(
'textarea')
text_area.send_keys(text)
def submit_underline_text(question_number, text): #下划线的填空题
text_area = questions[question_number].find_element_by_class_name(
'underline')
text_area.send_keys(text)
def submit_multi_text(question_number, answers_list): #多空填空题
text_area = questions[question_number].find_elements_by_class_name(
'underline')
for i in range(len(answers_list)):
text_area[i].send_keys(answers_list[i])
def next_page(): #翻页
next_button = driver.find_element_by_css_selector('#btnNext')
next_button.click()
questions = driver.find_elements_by_css_selector('.div_question')
def submit(): #交卷
driver.find_element_by_css_selector('#submit_button').click()
def main():
submit_text(0, '李狗蛋')
submit_choice(1, 'A')
submit_multi_choice(2, ['a', 'b', 'c', 'e'])
submit_choice(3, 'A')
submit_text(4, '司马光')
submit_multi_text(5, ['床前明月光', '举头望明月'])
submit_text(6, '打119')
next_page()
submit_choice(7, 'A')
submit()
input() #等待用户操作后再关闭浏览器
driver.close()
if __name__ == "__main__":
driver = webdriver.Chrome()
driver.get('https://ks.wjx.top/jq/71431917.aspx')
questions = driver.find_elements_by_css_selector('.div_question')
main()