Skip to content

Commit

Permalink
#12 #11 #7 #4 答题系列问题统一解决
Browse files Browse the repository at this point in the history
我摊牌了,搜题专门给你们分开来一个重新写。
  • Loading branch information
KirigiriSuzumiya committed May 7, 2022
1 parent 222fa97 commit 32bb6c4
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ P.S. 不保证都能用,打包不太靠谱。

P.S.S 电脑里要装有谷歌Chrome浏览器!!!



#### 一键运行.exe 使用说明:

**!!!!注目:url地址输入的是 旧版 超星网页网址。建议自己打开课程页面后复制!!!!**

示例:
Expand All @@ -61,6 +65,19 @@ P.S.S 电脑里要装有谷歌Chrome浏览器!!!



#### 一键做题.exe 使用说明:

介于各位学习通课程模板千奇百怪,我做了一个专门用来做题的小程序来分流压力

**!!!!注目:url地址输入的是 旧版 超星网页网址(带题目)。建议自己打开题目页面后复制!!!!**

**安全模式:**

- 不会自动提交,会点暂时保存
- 会生成question.txt,文件中会保留搜题记录,方便你进行简单的答案对照

**!!!!注目:第一次使用请记得打开安全模式,你们自己老师导入的题库可能会有随机题目导致0分!!!!**



------
Expand Down
152 changes: 152 additions & 0 deletions XueXiTong_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import random
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import Keys
import logging
from selenium.webdriver.remote.remote_connection import LOGGER

def question_resource(courseid, workid):
chrome_answer = webdriver.Chrome(executable_path="chromedriver.exe")
chrome_answer.get("https://mooc1.chaoxing.com/api/selectWorkQuestion?workId=%s&courseId=%s" % (workid, courseid))
qsts = chrome_answer.find_elements(By.CLASS_NAME, 'TiMu')
answers = []
for qst in qsts:
qst = qst.find_element_by_tag_name("div")
qst = qst.find_element_by_tag_name("div")
question_text = qst.text.replace('\n', '')
print(question_text)
answer = get_answer(question_text)
answers.append(answer)
return answers


def get_answer(question_text):
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# get直接返回,不再等待界⾯加载完成
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities["pageLoadStrategy"] = "none"
chrome = webdriver.Chrome(executable_path="chromedriver.exe", desired_capabilities=desired_capabilities)
chrome.get("https://cx.icodef.com/query.html?q=")
wait = WebDriverWait(chrome, 100)
wait.until(EC.presence_of_element_located((By.TAG_NAME, "input")))
chrome.execute_script('window.stop()')
chrome.find_element(By.TAG_NAME, "input").send_keys(question_text[question_text.find('】')+1:])
chrome.find_element(By.TAG_NAME, "input").send_keys(Keys.ENTER)
answer = []
wait.until(EC.presence_of_element_located((By.CLASS_NAME, "success")))
for i in chrome.find_elements(By.CLASS_NAME, "success"):
answer.append(i.text)
print("答案为:", answer)
if mode:
fp = open("answer.txt", "a+")
fp.writelines('\n' + question_text + '\n')
fp.writelines(answer)
return answer


def chapter_test_esp():
sleep(3)
#wait.until(EC.presence_of_element_located(chrome.find_element(By.TAG_NAME, "iframe")))
for iframe1 in chrome.find_elements(By.TAG_NAME, "iframe"):
#wait.until(EC.presence_of_element_located(chrome.find_element(By.TAG_NAME, "iframe")))
chrome.switch_to.frame(iframe1)
try:
chrome.find_element(By.TAG_NAME, "iframe")
except:
continue
for iframe2 in chrome.find_elements(By.TAG_NAME, "iframe"):
#wait.until(EC.presence_of_element_located(chrome.find_element(By.TAG_NAME, "iframe")))
chrome.switch_to.frame(iframe2)
try:
chrome.find_element(By.TAG_NAME, "iframe")
except:
continue
for iframe3 in chrome.find_elements(By.TAG_NAME, "iframe"):
#wait.until(EC.presence_of_element_located(chrome.find_element(By.TAG_NAME, "iframe")))
chrome.switch_to.frame(iframe3)
wait.until(EC.presence_of_all_elements_located((By.XPATH, "//div[@class='ZyTop']//span")))
if chrome.find_element(By.XPATH, "//div[@class='ZyTop']//span").text == "已完成":
chrome.switch_to.parent_frame()
print("该章节测试已提交,不用查题!")
continue
workid = chrome.find_element(By.ID, "oldWorkId").get_attribute("value")
courseid = chrome.find_element(By.ID, "courseId").get_attribute("value")
print("作业id:%s\t课程id:%s" % (workid, courseid))
answers = question_resource(courseid, workid)
qsts = chrome.find_elements(By.CLASS_NAME, 'TiMu')
count = 0
for qst in qsts:
qst = qst.find_elements_by_tag_name("li")
for answer in answers[count]:
if not answer:
print("未找到第%d题的答案!!!" % (count + 1))
elif answer[0] == 'A':
qst[0].click()
print("开始选择第%d题的答案:A" % (count + 1))
elif answer[0] == 'B':
qst[1].click()
print("开始选择第%d题的答案:B" % (count + 1))
elif answer[0] == 'C':
qst[2].click()
print("开始选择第%d题的答案:C" % (count + 1))
elif answer[0] == 'D':
qst[3].click()
print("开始选择第%d题的答案:D" % (count + 1))
elif answer[0] == '×':
qst[1].find_element(By.TAG_NAME, 'input').click()
print("开始选择第%d题的答案:×" % (count + 1))
elif answer[0] == '√':
qst[0].find_element(By.TAG_NAME, 'input').click()
print("开始选择第%d题的答案:√" % (count + 1))
count += 1
wait_time = random.randint(50, 150)
wait_time = float(wait_time) / 10
if mode:
print("该章节题目已答完!冷却%.2f秒后暂时保存!" % wait_time)
sleep(wait_time)
chrome.find_element(By.CLASS_NAME, 'btnGray_1').click()
wait.until(EC.alert_is_present())
chrome.switch_to.alert.accept()
else:
print("该章节题目已答完!冷却%.2f秒后提交!" % wait_time)
chrome.find_element(By.CLASS_NAME, 'Btn_blue_1').click()
wait.until(EC.presence_of_element_located((By.XPATH, "//a[@class='bluebtn ']")))
sleep(wait_time)
chrome.find_element(By.XPATH, "//a[@class='bluebtn ']").click()
chrome.switch_to.parent_frame()
chrome.switch_to.parent_frame()
chrome.switch_to.parent_frame()


print("输入网址url:")
url = input()
print("输入学习通用户名:")
username = input()
print("输入学习通密码:")
password = input()
print("是否开启安全模式(输入1开启),(0关闭):")
mode = input()
if mode == '1':
mode = True
else:
mode = False



LOGGER.setLevel(logging.CRITICAL)
options = webdriver.ChromeOptions()
options.add_argument('-ignore-certificate-errors')
options.add_argument('-ignore -ssl-errors')
chrome = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
chrome.get(url)
wait = WebDriverWait(chrome, 10)
chrome.find_element(By.CLASS_NAME, "ipt-tel").send_keys(username)
chrome.find_element(By.CLASS_NAME, "ipt-pwd").send_keys(password)
chrome.find_element(By.ID, "loginBtn").click()
print("登陆成功!")
print("请在切换到题目页后按enter键继续!")
input()
chapter_test_esp()
Binary file added 打包exe/一键做题.exe
Binary file not shown.

0 comments on commit 32bb6c4

Please sign in to comment.