Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/json; charset=utf-8');
- $opts = array(
- 'http'=>array(
- 'method'=>"GET",
- 'header'=>"x-requested-with: XMLHttpRequest\r\n"
- )
- );
- $context = stream_context_create($opts);
- $file = file_get_contents('https://baza-otvetov.ru/quiz/ask', false, $context);
- $content = explode("</script>", $file)[1];
- $p = xml_parser_create();
- xml_parse_into_struct($p, $content, $vals, $index);
- xml_parser_free($p);
- $id = $vals[0]["attributes"]["ID"];
- $question = $vals[0]["value"];
- $othercont = explode("</table>", explode("<table border='0' cellspacing='10'>", $content)[1])[0];
- $doc = new DOMDocument();
- $doc->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . $othercont);
- $tags = $doc->getElementsByTagName('h4');
- $_val = "";
- $vals = array();
- for ($i = 0; $i < $tags->length; $i++) {
- $val = $tags->item($i)->nodeValue;
- $data = array(
- 'q_id' => $id,
- 'answer' => $val
- );
- $postString = http_build_query($data, '', '&');
- $opts = array('http' =>
- array(
- 'method' => 'POST',
- 'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
- "x-requested-with: XMLHttpRequest\r\n",
- 'content' => $postString
- )
- );
- $context = stream_context_create($opts);
- $result = file_get_contents('https://baza-otvetov.ru/quiz/check', false, $context);
- $pravval = explode("<br /><br />", explode("<h3 style='color:#339966'>", $result)[1])[0];
- if ($pravval == "Правильно!") $_val = $val;
- array_push($vals, $val);
- }
- $resu = array(
- 'question'=> $question,
- 'answers'=> $vals,
- 'solve'=> $_val
- );
- echo json_encode($resu, JSON_UNESCAPED_UNICODE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement