Skip to content

Instantly share code, notes, and snippets.

@centerax
Created April 2, 2013 15:45
Show Gist options
  • Save centerax/5293244 to your computer and use it in GitHub Desktop.
Save centerax/5293244 to your computer and use it in GitHub Desktop.
<?php
ini_set('error_reporting', E_ERROR | E_PARSE);
ini_set('display_errors', 1);
$baseUrl = "http://www.brou.com.uy";
$data = file_get_contents($baseUrl . "/web/guest/institucional/cotizaciones");
$dom = new DOMDocument;
$dom->loadHTML($data);
//discard white space
$dom->preserveWhiteSpace = false;
//the table by its tag name
$tables = $dom->getElementsByTagName('table');
$rows = $tables->item(1)->getElementsByTagName('tr');
$x = array();
foreach ($rows as $row) {
$cols = $row->getElementsByTagName('td');
//@ToDo: Missing flag images and ISO currency code
if (null !== $cols->item(1)->nodeValue) {
$x[] = array(
'currency_label' => trim($cols->item(1)->nodeValue),
'buy' => trim($cols->item(2)->nodeValue),
'sell' => trim($cols->item(3)->nodeValue)
);
}
}
$xjson = json_encode($x);
var_dump($xjson);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment