Python Selenium 自动打分机器人:百分制、小分值、论坛打分全覆盖
需要加入的代码如下:
-
在AutoScore100类中添加start_forum_score()方法:
def start_forum_score(self): if not self.running: return
if self.forum_thread and self.forum_thread.is_alive(): return self.start_forum_button.config(state='disabled') self.stop_score_button.config(state='normal') self.update_running_label('论坛打分中...') self.forum_thread = Thread(target=self.forum_score_program) self.forum_thread.start() -
在AutoScore100类中添加forum_score_program()方法:
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: blank_message = self.browser.find_element(By.CLASS_NAME, "blank-message") if blank_message.text == "暂无": # 填写分值 score = random.randint(94, 99) forum_score_input.send_keys(str(score)) time.sleep(1.5) # 点击保存按钮 save_button = self.browser.find_element(By.XPATH, '//button[@ng-click="saveScore(currentEnrollment)"]') save_button.click() time.sleep(2.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('已
原文地址: https://www.cveoy.top/t/topic/f2eA 著作权归作者所有。请勿转载和采集!