Created
December 3, 2016 22:34
-
-
Save chongkan/c9ddc3ff0cbac83926b718150aa3a7e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
include('simple_html_dom.php'); | |
$propuestasPopularesAsamblea = new propuestasPopularesAsamblea(); | |
$propuestasPopularesAsamblea->index(); | |
class propuestasPopularesAsamblea { | |
protected $_minChars = 100; | |
public function index() { | |
// Create DOM from URL or file | |
$html = file_get_html('http://www.asamblea.go.cr/ca/Lists/Recepcin%20de%20iniciativas%20Populares/Principal.aspx'); | |
$propuestas = array(); | |
// Find the main table | |
foreach ($html->find('table') as $element) { | |
if (isset($element->summary)) { | |
foreach ($element->find('tr') as $tr) { | |
$propuesta = new STDClass(); | |
// Proponente | |
if (is_object($tr->find('td', 0))){ | |
$proponente = $tr->find('td', 0)->find('a', 0)->plaintext; | |
$propuesta->proponente = $proponente; | |
} | |
// Provincia | |
if (is_object($tr->find('td', 1))){ | |
$provincia = $tr->find('td', 1)->plaintext; | |
$propuesta->provincia = $provincia; | |
} | |
// Propuesta | |
if (is_object($tr->find('td', 2))){ | |
$descripcion = $tr->find('td', 2)->plaintext; | |
$propuesta->descripcion = htmlspecialchars_decode($descripcion); | |
} | |
// Fecha | |
if (is_object($tr->find('td', 3))){ | |
$fecha = $tr->find('td', 3)->plaintext; | |
$propuesta->fecha = $fecha; | |
} | |
if (isset($propuesta->descripcion) && strlen($propuesta->descripcion) >= $this->_minChars) { | |
$propuestas[] = $propuesta; | |
} | |
} // End foreach TR. | |
} // End foreach Content Table (Summary) | |
}// En foreach Table. | |
echo json_encode($propuestas); | |
// TODO | |
// Store in DB. | |
// Serve from DB. | |
// Only store latest additions. | |
} // End of Index Function. | |
} // End of Class. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment