网课比较麻烦,但是也比较容易,仅仅需要几段代码就可以实现自动刷课。由于本人初学爬虫,对于JavaScript也不是太熟悉,因此在网上找了一些代码,对其进行一下汇总。
打开浏览器,在智慧树网课播放界面按F12 在第二个Console界面复制下面的任意一段代码按enter就可以了,挂着就能自动刷了。
代码一:
写在前面,改代码可以实现1.5倍速播放,静音播放,自动播放下一集,但是不能跳过弹出的习题
(function () {
const MAX_DELAY = 60 // 切课时的最大延迟,单位:秒
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time))
const start = async function () {
console.log('智慧树助手已启动')
while (true) {
console.log('正在检查')
const delay = Math.floor(Math.random() * MAX_DELAY * 1000) + 1000
if (!/1.5/.test($('.speedBox').attr('style'))) {
console.log('提升到1.5倍速')
$('.speedTab15').click()
}
if (!/liuchang/.test($('.definiBox').attr('style'))) {
console.log('更改画质')
$('.line1bq').click()
}
if ($('.volumeBox').find('.passVolume').width() != 0) {
console.log('静音')
$('.volumeIcon').click()
}
if ($('.playButton').length > 0) {
console.log('点击播放')
$('.playButton').click()
}
if ($('.popbtn_cancel')[0]) {
console.log('发现弹题,将在' + delay / 1000 + ' 秒后点击关闭')
await sleep(delay)
$('.popbtn_cancel').click()
}
if ($('.current_play').find('.progressbar').width() == $('.current_play').find('.progressbar_box').width()) {
console.log('本节完成,' + delay / 1000 + ' 秒后将切到下一课')
await sleep(delay)
$('.current_play').nextAll('.video')[0].click()
}
await sleep(1000)
}
}
start()
}())
代码二:
写在前面,改代码可以实现1.5倍速播放,静音播放,自动播放下一集,并且可以自动跳过习题。
var ti = $("body");
var video = $(".catalogue_ul1 li[id*=video-]");
var i = 1;
var v = 1;
video.css("color", "blue");
console.log("已选取" + video.length + "个小节,并已用蓝色标明,请检查是否有遗漏,如有遗漏,概不负责");
setTimeout(function () {
$('.speedTab15').click();
$('.volumeIcon').click();
console.log("已进行静音和1.5倍加速");
}, 3000);
ti.on("DOMNodeInserted", function (e) {
if (e.target.textContent == "关闭") {
console.log("检测到第" + i + "个弹题窗口");
window.setTimeout(function () {
document.getElementById("tmDialog_iframe").contentWindow.document.getElementsByClassName("answerOption")[0].getElementsByTagName("input")[0].click();
$(".popbtn_cancel").click();
console.log("已关闭");
}, 3000);
i++;
} else if (e.target.textContent == "本节视频,累计观看时间『100%』") {
console.log("检测到视频观看完成,准备跳到下一节");
$('.next_lesson_bg').find('a').trigger('click');
console.log("已跳转");
setTimeout(function () {
$('.volumeIcon').click();
$('.speedTab15').click();
console.log("已进行静音和1.5倍加速");
}, 6000);
v++;
console.log("目前播放了" + v + "个视频");
}
});
代码三:
写在前面,改代码可以实现1.5倍速播放,不能静音播放,自动播放下一集,并且可以自动跳过习题。
function timeCount()
{
if(document.getElementById('popbox_title')) {
var x = document.getElementsByClassName('popbtn_cancel');
window.clearInterval();
x[0].click();
console.log('关闭窗口');
}
}
var time=0;
var father=document.getElementById("my");
var divs = document.createElement("div");
divs.id='mybutton';
divs.style.position='fixed';
divs.style.left='150px';
divs.style.top='100px';
divs.style.width='72px';
divs.style.height='72px';
divs.style.backgroundImage="url('data:image/png;base64,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')";
divs.onclick=function(){
setTimeout(function(){
console.log('切换到1.5倍');
document.getElementsByClassName('speedTab15')[0].click();
},5000);
if(time===0){
alert('已经启动,可以最小化了');
}else{
console.log('第二次初始化');
}
//视频播放暂停
document.getElementById("vjs_mediaplayer_html5_api").onpause = function() {
console.log('已暂停');
window.setInterval(timeCount(),700);
};
//视频播放结束
document.getElementById("vjs_mediaplayer_html5_api").onended=function(){
console.log('已结束');
setTimeout(function(){
//document.getElementsByClassName('next_lesson_bg tm_next_lesson')[0].click();
document.getElementById('nextBtn').click();
setTimeout(function(){
time=1;
divs.click();
},5000);
},2500);
};
};
document.body.appendChild(divs);