[title]原理[/title]
- 穷举法获取题库
- 油猴脚本答题
- 手动提交
[title]客户端[/title]
TamperMonkey脚本// ==UserScript==
// @name luobeigo考试辅助
// @namespace luobeigo
// @version 0.1
// @description get nice grade
// @author kamino
// @match http://exam.luobeigo.com/index.php?exam-app-exam-paper
// @grant none
// ==/UserScript==
$(function () {
const formHtml = $('form').html();
$.ajax({
url: 'http://localhost/jb/query.php',
data: {
'data': formHtml
},
type: 'post',
dataType: 'json',
timeout: 10000,
success: function (result, status, xhr) {
console.log(result);
if (status === 'success') {
startAnswer(result)
}
},
error: function (xhr, status, error) {
console.log(xhr + status + error)
}
});
function startAnswer(result) {
for (let i = 0; i < result.length; i++) {
console.log("no. " + i);
let qtid = result[i]['id'];
let qtas = result[i]['ans'];
for (let j = 0; j < qtas.length; j++) {
console.log(qtas[j]);
$("input[rel='" + qtid + "'][value='" + qtas[j] + "']").click()
}
}
}
});
[title]服务端[/title]
搜索答案功能使用的项目
simple_html_dom、 wcurl
数据库
database: luobeigo
table: answer(id, ans)
<?php
/**
* Author: kamino
* CreateTime: 2018/7/1,上午 09:36
* Description:
* Version:
*/
header( "Access-Control-Allow-Origin: *" );
require_once "lib/htmldom.class.php";
function loadExam( $html = "" ) {
$qtAll = fHtml( $html, "div.paperexamcontent" );
//$qtNum = count( $qtAll );
$qtList = array();
foreach ( $qtAll AS $id => $qt ) {
$qtList[ $id ]["id"] = trim( str_replace( "questions_", "", $qtAll[ $id ]->id ) );
//$qtList[ $id ]["title"] = str_replace( "<a name=\"question_{$qtList[ $id ]["id"]}\"> </a>", "", trim( fHtml( $qtAll[ $id ], "div.choice", 0 )->innertext ) );
//$choice = trim( fHtml( $qtAll[ $id ], "div.choice", 1 )->innertext );
//$qtList[ $id ]["choice"]["A"] = trim( fHtml( $choice, "p", 0 )->innertext );
//$qtList[ $id ]["choice"]["B"] = trim( fHtml( $choice, "p", 1 )->innertext );
//$qtList[ $id ]["choice"]["C"] = trim( fHtml( $choice, "p", 2 )->innertext );
//$qtList[ $id ]["choice"]["D"] = trim( fHtml( $choice, "p", 3 )->innertext );
}
return $qtList;
}
function fHtml( $data, $tag, $id = - 1 ) {
$shd = new simple_html_dom();
$shd->load( $data );
return $id >= 0 ? $shd->find( $tag, $id ) : $shd->find( $tag );
}
function getAnswer( $id ) {
$conn = new mysqli( "localhost", "username", "password", "luobeigo" );
if ( $conn->connect_error ) {
die( $conn->error );
}
$result = $conn->query( "SELECT `ans` FROM `answer` WHERE `id` = '{$id}';" );
if ( $result->num_rows != 1 ) {
return false;
}
$row = $result->fetch_assoc();
$str = array();
for ( $i = 0; $i < strlen( $row["ans"] ); $i ++ ) {
$str[] = $row["ans"][ $i ];
}
return $str;
}
function main() {
//$data = file_get_contents( "tmp.html" );
$data = $_POST["data"];
$list = loadExam( $data );
$responseArr = array();
foreach ( $list as $i => $item ) {
$responseArr[ $i ]["id"] = $item["id"];
$responseArr[ $i ]["ans"] = getAnswer( $item["id"] );
}
return json_encode( $responseArr );
}
echo main();
穷举题库功能
<?php
/**
* Author: kamino
* CreateTime: 2018/7/1,上午 10:55
* Description:
* Version:
*/
require_once "lib/wcurl.class.php";
require_once "lib/htmldom.class.php";
//cookie换成自己的
define( "COOKIE", "" );
function getPage( $ehid ) {
$wch = new wcurl( "http://exam.luobeigo.com/index.php?exam-app-history-view=&ehid=" . $ehid );
return $wch->addCookie( COOKIE )->get();
}
function fHtml( $data, $tag, $id = - 1 ) {
$shd = new simple_html_dom();
$shd->load( $data );
return $id >= 0 ? $shd->find( $tag, $id ) : $shd->find( $tag );
}
function loadAnswer( $html ) {
$ansAll = fHtml( $html, "div.paperexamcontent" );
$ansNum = count( $ansAll );
$ansList = array();
foreach ( $ansAll AS $id => $ans ) {
$ansList[ $id ]["id"] = trim( str_replace( "question_", "", fHtml( $ansAll[ $id ], "a", 1 )->name ) );
$ansList[ $id ]["ans"] = trim( fHtml( $ansAll[ $id ], "td", 1 )->innertext );
queryAdd( $ansList[ $id ]["id"], $ansList[ $id ]["ans"] );
}
return $ansList;
}
function queryAdd( $id, $ans ) {
$conn = new mysqli( "localhost", "username", "password", "luobeigo" );
if ( $conn->connect_error ) {
die( $conn->error );
}
if ( $conn->query( "SELECT * FROM `answer` WHERE `id` = '{$id}';" )->num_rows != 0 ) {
$conn->close();
return;
}
if ( $conn->query( "INSERT INTO `answer` (`id`, `ans`) VALUES ('{$id}', '{$ans}');" ) ) {
echo "add success {$id}" . PHP_EOL;
$conn->close();
return;
}
$conn->close();
echo "fail {$id}" . PHP_EOL;
}
function main() {
for ( $i = 77; $i <= 600; $i ++ ) {
echo "EXAM: " . $i . PHP_EOL;
$html = getPage( $i );
$list = loadAnswer( $html );
//file_put_contents( "save/" . $i . ".json", json_encode( $list ) );
}
}
main();
[title]代码和题库sql[/title]
立即下载
文章评论