加入功能的代码:

创建“论坛打分”按钮

forum_frame = tk.Frame(self.root) forum_frame.pack(pady=10) self.start_forum_button = tk.Button(forum_frame, text='论坛打分', command=self.start_forum_score) self.start_forum_button.pack(side=tk.LEFT, padx=20)

修改论坛打分函数

def forum_score_program(self): try: # 循环打分论坛分值 while True: if not self.running: break

        if self.paused:
            continue

        # 等待论坛打分输入框出现
        while True:
            try:
                forum_score_input = self.browser.find_element(By.XPATH,
                                                              '//input[@ng-model="currentEnrollment.forum_score.'
                                                              'display_score"]')
                break
            except:
                pass
            time.sleep(3)

        # 判断是否有内容
        try:
            forum_post_number = self.browser.find_element(By.CLASS_NAME, "sum_of_posts").text
            if int(forum_post_number) >= 1:
                # 填写分值
                score = random.randint(94, 99)
                forum_score_input.clear()
                forum_score_input.send_keys(str(score))
                time.sleep(1.5)
                self.update_text_box(f"本次论坛分值为:{score}")
                self.update_running_label('论坛打分中...')
            else:
                self.update_text_box("该学生论坛未提交")
        except:
            pass

        # 点击下一个学生
        next_student_element = self.browser.find_element(By.XPATH, '//i[@ng-click="goToNextStudent()"]')
        if "disabled" in next_student_element.get_attribute("class"):
            print("已经到最后一个学生")
            self.update_running_label('已到最后,请手动保存后重新开始!')
            break
        else:
            next_student_element.click()
            time.sleep(3)
            self.update_running_label('论坛打分中...')

except Exception as e:
    print(e)
    self.update_running_label('论坛打分失败,请重试')
finally:
    self.start_forum_button.config(state='normal')
    self.stop_score_button.config(state='disabled')
    self.pause_button.config(state='disabled')

需要修改的位置:

判断是否有内容

try: forum_post_number = self.browser.find_element(By.CLASS_NAME, "sum_of_posts").text if int(forum_post_number) >= 1: # 填写分值 score = random.randint(94, 99) forum_score_input.clear() forum_score_input.send_keys(str(score)) time.sleep(1.5) self.update_text_box(f"本次论坛分值为:{score}") self.update_running_label('论坛打分中...') else: self.update_text_box("该学生论坛未提交") except: pass

自动评分机器人:高效便捷的评阅助手

原文地址: https://www.cveoy.top/t/topic/f2gE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录