(quiz_type, cookies, scores, score_all, quiz_xpath, category_xpath, uid=None, driver_default=None)
| 51 | |
| 52 | @exception_catcher() |
| 53 | def answer_question(quiz_type, cookies, scores, score_all, quiz_xpath, category_xpath, uid=None, driver_default=None): |
| 54 | quiz_zh_CN = {"daily": "每日", "weekly": "每周", "zhuanxiang": "专项"} |
| 55 | if(quiz_type not in ["daily", "weekly", "zhuanxiang"]): |
| 56 | print("quiz_type 错误。收到的quiz_type:"+quiz_type) |
| 57 | exit(0) |
| 58 | if uid is None: |
| 59 | uid = user.get_userId(cookies) |
| 60 | if scores[quiz_type] < score_all: # 还没有满分,需要答题 |
| 61 | if driver_default is None: |
| 62 | driver_ans = Mydriver(nohead=gl.nohead) |
| 63 | ##### driver_ans = Mydriver(nohead=True) |
| 64 | else: |
| 65 | driver_ans = driver_default |
| 66 | driver_daily = driver_ans |
| 67 | driver_weekly = driver_ans |
| 68 | driver_zhuanxiang = driver_ans |
| 69 | # try: |
| 70 | # nohead = gl.nohead |
| 71 | # except: |
| 72 | # nohead=False |
| 73 | # if nohead: |
| 74 | # print("使用默认窗口大小") |
| 75 | # else: |
| 76 | driver_ans.driver.maximize_window() |
| 77 | print('请保持窗口最大化\n'*3) |
| 78 | driver_ans.get_url("https://www.xuexi.cn/notFound.html") |
| 79 | driver_ans.set_cookies(cookies) |
| 80 | pass_count = 0 |
| 81 | # 最大值,用于nohead模式退出 |
| 82 | max_count = 0 |
| 83 | # 从数据库获取答案 |
| 84 | answer_from_db = False |
| 85 | answer_error_max = cfg_get("parameter.answer_error_max", 100) |
| 86 | # 是否开启错题收集 |
| 87 | answer_error_collect = cfg_get("parameter.answer_error_collect", True) |
| 88 | if scores[quiz_type] < score_all: |
| 89 | letters = list("ABCDEFGHIJKLMN") |
| 90 | driver_ans.get_url('https://pc.xuexi.cn/points/my-points.html') |
| 91 | refresh_my_page_count = 0 |
| 92 | # 页面title为积分则一直循环 |
| 93 | while driver_ans.title_is(u"我的积分") and refresh_my_page_count < 20: |
| 94 | time.sleep(1) # 等待页面刷新提示 |
| 95 | refresh_buttons = driver_ans.driver.find_elements_by_css_selector( |
| 96 | ".ant-modal-wrap .ant-btn:not(.ant-btn-primary)") |
| 97 | if len(refresh_buttons) > 0: # |
| 98 | refresh_buttons[0].click() |
| 99 | driver_ans.click_xpath(quiz_xpath) # 点击各个题目的去答题按钮 |
| 100 | time.sleep(1) |
| 101 | refresh_my_page_count += 1 |
| 102 | if refresh_my_page_count >= 20: |
| 103 | print("没有找到答题按钮") |
| 104 | if quiz_type != "daily": # 如果是每日答题就不用找available了 |
| 105 | # 此处修改是因为页面可能刷新后导致的查找元素button 丢失从而引发异常重新此处用可以重新查找来解决 |
| 106 | try: |
| 107 | to_click = find_available_quiz(quiz_type, driver_ans, uid) |
| 108 | except Exception as e: |
| 109 | to_click = find_available_quiz(quiz_type, driver_ans, uid) |
| 110 | if to_click is not None: |
no test coverage detected