Last active
May 21, 2021 14:27
-
-
Save crashmax-dev/f423f02ce017f8b878833a59ff999999 to your computer and use it in GitHub Desktop.
Driving test (https://eteenindus.mnt.ee/public/vabadSoidueksamiajad.xhtml)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: application/json'); | |
header('Access-Control-Allow-Credentials: false'); | |
header("Access-Control-Allow-Origin: *"); | |
require "../vendor/autoload.php"; | |
use PHPHtmlParser\Dom; | |
$dom = new Dom; | |
$dom->load('https://eteenindus.mnt.ee/public/vabadSoidueksamiajad.xhtml'); | |
$tbody = $dom->find('tbody > tr'); | |
if (count($tbody) > 0) { | |
$thead = $dom->find('.eksam-ajad-uuendatud > span'); | |
$last_update = explode(": ", $thead->innerHtml)[1]; | |
$data = []; | |
for ($i = 0; $i < count($tbody); $i++) { | |
$location = $tbody[$i]->find('td > span')->innerHtml; | |
$data[$location] = array( | |
$tbody[$i]->find('td')[2]->innerHtml, | |
$tbody[$i]->find('td')[3]->innerHtml, | |
$tbody[$i]->find('td')[4]->innerHtml, | |
); | |
} | |
echo json_encode(array( | |
'ok' => true, | |
'last_update' => $last_update, | |
'data' => $data)); | |
} else { | |
echo json_encode(array('ok' => false)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment