把抓取来的代码发送给OJ的判题页面,即可实现AC
<?php header("Content-type: text/html; charset=utf-8"); $dbms = 'mysql'; $host = 'localhost'; $dbname = 'application'; $user = 'jtahstu'; $pass = 'jtahstu'; $dsn = "$dbms:host=$host;dbname=$dbname"; try { $dbh = new PDO($dsn, $user, $pass); $dbh -> exec("set names utf8"); foreach ($dbh->query ( "select * from nyojAcCode where pid>1243;" ) as $row) { $pid = $row['pid']; $data = array('btn_submit' => '提交', 'code' => $row['code'], 'language' => ' C/C++'); // 初始化一个 cURL 对象 $curl = curl_init(); // 设置你需要抓取的URL curl_setopt($curl, CURLOPT_URL, 'http://acm.nyist.net/JudgeOnline/submit.php?pid=' . $pid); // 设置header curl_setopt($curl, CURLOPT_HEADER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_COOKIE, "PHPSESSID=c1895521e889621a79413ec0a637c194"); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // 运行cURL,请求网页 $data = curl_exec($curl); // 关闭URL请求 curl_close($curl); echo "第".$pid."题提交成功!<br>"; sleep(1); } } catch (PDOException $e) { die("Error!: " . $e -> getMessage() . "<br/>"); } ?>
---
本文章采用 知识共享署名2.5中国大陆许可协议 进行许可,转载必须注明作者和本文链接。
---
发表评论