基于Python和selenium的内蒙古继续教育网---刷课
本帖最后由 lntuer 于 2019-9-16 18:14 编辑目标网址:https://www.nmgjxjy.com/
解决问题:所选课程全部自动化
运行环境:Python3、selenium、chrome、pyautogui
声明:仅限个人学习使用,严禁商业使用,否则后果自负(如有违规请版主删除)
登陆网址
课程目录
单个课程目录
单个视频
from selenium import webdriver
import pyautogui
import time
import re
#个人账号
username=pyautogui.prompt("请输入账号:")
#个人密码
passwd=pyautogui.prompt("请输入密码:")
login_url='https://www.nmgjxjy.com'
lesson_url='https://www.nmgjxjy.com/user/packets?flag=studying'
option = webdriver.ChromeOptions()
browser = webdriver.Chrome( chrome_options=option)
browser.maximize_window()
browser.get(login_url)
browser.implicitly_wait(10)
elem=browser.find_element_by_class_name("userNmae")
elem.send_keys(username)
time.sleep(1)
elem=browser.find_element_by_class_name("userPwd")
elem.send_keys(passwd)
time.sleep(1)
code_num=pyautogui.prompt("请输入验证码:")
elem=browser.find_element_by_class_name("userCode")
elem.send_keys(code_num)
elem=browser.find_element_by_xpath('/html/body/div/div/div/div/div/div/form/div/input')
elem.click()
time.sleep(3)
browser.find_element_by_xpath('/html/body/div/div/ul/li/a/span').click()
time.sleep(3)
num=browser.find_elements_by_class_name("td_02")
print(len(num))
for i in range(0,len(num)):
lesson_xpath="/html/body/div/div/div/div/div/div/table/tbody/tr["+str(2+i)+"]/td/a/img"
browser.find_element_by_xpath(lesson_xpath).click()
window = browser.window_handles
browser.switch_to_window(window[-1])
time.sleep(5)
next_num=re.findall("autoff",browser.page_source)
video_time=re.findall("\'0\'\,\'3\',\'(.*?)\'\,\'5",browser.page_source)
tr_id=re.findall('id="(autoff.*?)">',browser.page_source)
print(len(next_num))
print(video_time)
print(tr_id)
for g,m in zip(tr_id,video_time) :
xpath_code = '//*[@id="' + str(g) + '"]/td/a/img'
watched_id = browser.find_element_by_xpath('//*[@id="' + str(g) + '"]/td').text
print(watched_id) //增加一个判断、判断该视频是否已学习完
if watched_id == "否":
browser.find_element_by_xpath(xpath_code).click()
# 延迟100秒
lesson_timeout = int(str(m).split(".")[0]) * 60 + int(str(m).split(".")[1]) + 100
print(lesson_timeout)
time.sleep(lesson_timeout)
browser.back()
time.sleep(1)
browser.switch_to_alert().accept()
time.sleep(3)
browser.find_element_by_xpath('/html/body/div/div/ul/li/a/span').click()
time.sleep(3) from selenium import webdriver
import pyautogui
import time
import re
#个人账号
username=pyautogui.prompt("请输入账号:")
#个人密码
passwd=pyautogui.prompt("请输入密码:")
login_url='https://www.nmgjxjy.com'
lesson_url='https://www.nmgjxjy.com/user/packets?flag=studying'
option = webdriver.ChromeOptions()
browser = webdriver.Chrome( chrome_options=option)
browser.maximize_window()
browser.get(login_url)
browser.implicitly_wait(10)
elem=browser.find_element_by_class_name("userNmae")
elem.send_keys(username)
time.sleep(1)
elem=browser.find_element_by_class_name("userPwd")
elem.send_keys(passwd)
time.sleep(1)
code_num=pyautogui.prompt("请输入验证码:")
elem=browser.find_element_by_class_name("userCode")
elem.send_keys(code_num)
elem=browser.find_element_by_xpath('/html/body/div/div/div/div/div/div/form/div/input')
elem.click()
time.sleep(3)
browser.find_element_by_xpath('/html/body/div/div/ul/li/a/span').click()
time.sleep(3)
num=browser.find_elements_by_class_name("td_02")
print(len(num))
for i in range(0,len(num)):
lesson_xpath="/html/body/div/div/div/div/div/div/table/tbody/tr["+str(2+i)+"]/td/a/img"
browser.find_element_by_xpath(lesson_xpath).click()
window = browser.window_handles
browser.switch_to_window(window[-1])
time.sleep(5)
next_num=re.findall("autoff",browser.page_source)
video_time=re.findall("\'0\'\,\'3\',\'(.*?)\'\,\'5",browser.page_source)
tr_id=re.findall('id="(autoff.*?)">',browser.page_source)
print(len(next_num))
print(video_time)
print(tr_id)
for g,m in zip(tr_id,video_time) :
xpath_code = '//*[@id="' + str(g) + '"]/td/a/img'
watched_id = browser.find_element_by_xpath('//*[@id="' + str(g) + '"]/td').text
print(watched_id) //增加一个判断、判断该视频是否已学习完
if watched_id == "否":
browser.find_element_by_xpath(xpath_code).click()
# 延迟100秒
lesson_timeout = int(str(m).split(".")) * 60 + int(str(m).split(".")) + 100
print(lesson_timeout)
time.sleep(lesson_timeout)
browser.back()
time.sleep(1)
browser.switch_to_alert().accept()
time.sleep(3)
browser.find_element_by_xpath('/html/body/div/div/ul/li/a/span').click()
time.sleep(3) 沙卡丶拉卡 发表于 2019-9-2 13:23
纯小白,发的是源码吗,是怎么使用的呢,继续教育太费事儿了555
Python和selenium 楼主可以啊 支持 强!!!!!!!!!!!!11 虽然不知道啥用,猜测是不是不用学习扒学分的,帮顶了 网站名字很牛逼啊
谢谢楼主分享 好牛的工具啊,支持一下。 求河北专技刷课 纯小白,发的是源码吗,是怎么使用的呢,继续教育太费事儿了555{:1_937:}