type
Post
status
Published
date
Dec 23, 2021
slug
中国大学MOOC自动互评自评——基于python-selenium库
summary
中国大学MOOC自动互评自评——基于python selenium库
tags
MOOC
selenium
category
Python
icon
password
Property
Jul 13, 2022 07:56 AM

使用

1.下载fuckMOOC.py
1.配置依赖
2.填写数据
3.运行等待

1.下载fuckMOOC.py

项目地址:
GitHub - lylelove/fuckMOOC: 🏫中国大学MOOC自动互评自评--基于python selenium库
1.下载fuckMOOC.py 1.配置依赖 2.填写数据 3.运行等待 1.下载fuckMOOC.py 2.配置依赖 a.安装python win10及以上使用组合键win+r调出运行,打开cmd,在控制台输入 python3 直接在微软商店安装即可。 安装完成后通过输入 python3 -v 查看是否安装正常。 b.安装pip 下载地址: https://pypi.python.org/pypi/pip 一般python都集成了pip,可以在cmd中键入 pip 进行验证。 c.安装selenium 通过 pip install selenium 安装 d.下载浏览器驱动 下载链接: https://www.selenium.dev/downloads/ 本人使用的是chrome浏览器,chrome浏览器也可以用这个地址下载: http://chromedriver.storage.googleapis.com/index.html。接下来以chrome浏览器为例。 下载驱动后将驱动(chromedriver.exe)放到Chrome的安装路径下,例如 C:\Program Files (x86)\Google\Chrome\Application ,然后把改路径加入到环境变量Path中。我的电脑->属性->高级系统设置->环境变量--System变量Path增加 ;C:\Program Files (x86)\Google\Chrome\Application e.查看是否安装成功 在cmd键入 python3,之后键入 from selenium import webdriver,未报错即为安装成功。 3.填写数据 在fuckMOOC.py中填写手机号、密码、课程地址 课程地址例如: https://www.icourse163.org/course/SDCJDX-1449597161 4.运行等待 右键fuckMOOC.py文件,选择打开方式,选择python3,打开。 然后等待。 本项目中的js代码来源于@XenoAmess,在此致谢。
GitHub - lylelove/fuckMOOC: 🏫中国大学MOOC自动互评自评--基于python selenium库

2.配置依赖

a.安装python
win10及以上使用组合键win+r调出运行,打开cmd,在控制台输入python3直接在微软商店安装即可。
安装完成后通过输入python3 -v查看是否安装正常。
b.安装pip
一般python都集成了pip,可以在cmd中键入pip进行验证。
c.安装selenium
通过pip install selenium安装
d.下载浏览器驱动
本人使用的是chrome浏览器,chrome浏览器也可以用这个地址下载:http://chromedriver.storage.googleapis.com/index.html。接下来以chrome浏览器为例。
下载驱动后将驱动(chromedriver.exe)放到Chrome的安装路径下,例如 C:\Program Files (x86)\Google\Chrome\Application ,然后把改路径加入到环境变量Path中。我的电脑->属性->高级系统设置->环境变量--System变量Path增加 ;C:\Program Files (x86)\Google\Chrome\Application
e.查看是否安装成功
在cmd键入python3,之后键入from selenium import webdriver,未报错即为安装成功。

3.填写数据

在fuckMOOC.py中填写手机号、密码、课程地址。

4.运行等待

右键fuckMOOC.py文件,选择打开方式,选择python3,打开。
然后等待。

本项目中的js代码来源于@XenoAmess,在此致谢。
 
# coding = utf-8import time from seleniumimport webdriver from selenium.webdriver.common.byimport By from selenium.webdriver.supportimport expected_conditions from selenium.webdriver.support.waitimport WebDriverWait tele= ''##手机号password= ''##密码course= "https://www.icourse163.org/course/SDCJDX-1449481165"##课程地址json= 'var REFRESH_TIME=100;var REG=RegExp(/^http(s)?:\/\/www\.icourse163\.org\/.*\/learn\/hw.*/);var COMMENT_STRINGS_LIST=[];COMMENT_STRINGS_LIST[0]="很好";function getRandomInt(max){return Math.floor(Math.random()*Math.floor(max))}function doIt(){if(window.location.href.match(REG)==null){return}return doItNonCheck()}function parseFloatEx(string){var res="";for(var i=0;i<string.length;i++){var chr=string.charAt(i);if((chr>="0"&&chr<="9")||chr==="."){res+=chr}}return parseFloat(res)}function doItNonCheck(){var i,j,k;if(!window.jQuery){var oScript=document.createElement("script");oScript.type="text/javascript";oScript.src="//s1.hdslb.com/bfs/static/jinkela/long/js/jquery/jquery1.7.2.min.js";document.head.appendChild(oScript)}var scorePanelList=$("div.detail>div.s");for(i=0;i<scorePanelList.length;i++){var scorePanel=scorePanelList[i];var maxScore=-1;var maxIndex=-1;for(j=0;j<scorePanel.children.length;j++){for(k=0;k<scorePanel.children[j].children.length;k++){if(scorePanel.children[j].children[k].type==="radio"){var nowScore=parseFloatEx(scorePanel.children[j].children[k].value);var nowIndex=j;if(maxScore<nowScore){maxScore=nowScore;maxIndex=nowIndex}}}}console.log("maxIndex:"+maxIndex);console.log("maxScore:"+maxScore);if(maxIndex!==-1){for(k=0;k<scorePanel.children[maxIndex].children.length;k++){if(scorePanel.children[maxIndex].children[k].type==="radio"){console.log($(scorePanel.children[maxIndex].children[k]));$(scorePanel.children[maxIndex].children[k]).attr("checked","true")}}}}var commentTextAreaList=$("textarea.j-textarea.inputtxt");for(i=0;i<commentTextAreaList.length;i++){var commentTextArea=commentTextAreaList[i];if(commentTextArea.value===undefined||commentTextArea.value===null||commentTextArea.value===""||commentTextArea.value.length===0){commentTextArea.value=COMMENT_STRINGS_LIST[getRandomInt(COMMENT_STRINGS_LIST.length)]}}}(function(){"use strict";window.onload=window.setInterval(doIt,REFRESH_TIME)})();' driver= webdriver.Chrome() driver.get(course) driver.find_element(By.PARTIAL_LINK_TEXT, "登录").click() driver.find_element(By.XPATH, "/html/body/div[13]/div[2]/div/div/div/div/div[2]/span").click() driver.find_element(By.XPATH, "/html/body/div[13]/div[2]/div/div/div/div/div/div[1]/div/div[1]/div[1]/ul/li[2]").click() iframe= driver.find_element(By.XPATH, "/html/body/div[13]/div[2]/div/div/div/div/div/div[1]/div/div[1]/div[2]/div[2]/div/iframe") driver.switch_to.frame(iframe) login=(By.XPATH,"/html/body/div[2]/div[2]/div[2]/form/div/div[6]/a") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.ID, "phoneipt").send_keys(tele) driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[2]/form/div/div[4]/div[2]/input[2]").send_keys(password) driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div[2]/form/div/div[6]/a").click() login= (By.XPATH, "/html/body/div[4]/div[2]/div[1]/div/div[3]/div/div[2]/div/div[2]/div[2]/div/span") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[1]/div/div[3]/div/div[2]/div/div[2]/div[2]/div/span").click() time.sleep(0.5) try: driver.find_element(By.XPATH, "/html/body/div[10]/div/div[2]/div/div/p/label/label/input").click() driver.find_element(By.XPATH, "/html/body/div[10]/div/div[1]/a").click() except: print(1) driver.find_element(By.LINK_TEXT, "测验与作业").click() login= (By.XPATH,"/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/h2") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) unitz=Falseunit=1 whilenot unitz: try: driver.find_element(By.XPATH,"/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div["+ str( unit+1)+ "]/*/*/a[text()='前往作业']") unit=unit+1 except: unit=unit unitz=Trueprint(unit) driver.execute_script(json) for numin range(1, unit): units= "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div["+ str( num+ 1)+ "]/*/*/a[text()='前往作业']" login= (By.XPATH,units) WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, units).click() login= (By.XPATH,"/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div/div[2]/div[3]/div[1]") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) flag=Falsetry: driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div/div[2]/div[2]/a").click() login= (By.LINK_TEXT,"提交") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) whilenot flag: driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[4]/a[3]").click() login= (By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[1]/p[2]/a") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[1]/p[2]/a").click() if driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div/div[2]/div[3]/div[1]").get_attribute( 'class')== "f-fl status undone j-status done": flag=Trueelse: flag=Falsedriver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div").click() except: try: driver.find_element(By.LINK_TEXT, "继续进行互评").click() login= (By.LINK_TEXT, "提交") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) whilenot flag: driver.execute_script(json) login= (By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[4]/a[3]") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[4]/a[3]").click() login= (By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[1]/p[2]/a") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[1]/p[2]/a").click() if driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div/div[2]/div[3]/div[1]").get_attribute( 'class')== "f-fl status undone j-status done": flag=Trueelse: flag=Falsedriver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div").click() except: driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div").click() for numin range(1, unit): units= "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div["+ str( num+ 1)+ "]/*/*/a[text()='前往作业']" login= (By.XPATH, units) WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, units).click() login= (By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div/div[2]/div[3]/div[1]") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) if driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[2]/div/div[2]/div[4]/div").get_attribute( 'class')== "f-fl status undone j-status": driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div/table/tbody/tr/td[2]/a").click() driver.execute_script(json) login= (By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[4]/a[3]") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[3]/div/div[4]/a[3]").click() login= (By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div").click() login= (By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div") WebDriverWait(driver, 60, 0.5).until(expected_conditions.presence_of_element_located(login)) driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div").click() else: driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/div[4]/div[2]/div/div[1]/div/div[1]/div").click()
爬取哔哩哔哩历史——基于selenium-pyecharts库免费域名注册

  • Waline
  • Giscus