Skip to content

Commit

Permalink
created table method
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris DeGroat committed Sep 16, 2014
1 parent a4329d9 commit f13ad51
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions zamboni.php
Expand Up @@ -3,6 +3,20 @@
class zamboni
{
private $html = NULL;
private $error = NULL;

public function __construct($string = NULL)
{
if(!empty($string))
{
$this->load_from_string($string);
}
}

public function html()
{
return $this->html;
}

public function load_from_url($url, $referrer = NULL, $user_agent = NULL)
{
Expand All @@ -21,6 +35,17 @@ public function load_from_url($url, $referrer = NULL, $user_agent = NULL)
}

$this->html = curl_exec($c);
if(curl_errno($c))
{
$this->error = curl_error($c);
return FALSE;
}
return TRUE;
}

public function error()
{
return $this->error;
}

public function load_from_file($filename)
Expand All @@ -33,7 +58,18 @@ public function load_from_string($string)
$this->html = $string;
}

public function extract($table_selector, $nth_table = 1, $row_selector = 'tr', $header_row = TRUE)
public function extract($selector, $nth = 1)
{
$html = str_get_dom($this->html);
$block = $html($selector, $nth-1);
if(!method_exists($block, 'getInnerText'))
{
return NULL;
}
return $block->getInnerText();
}

public function table($table_selector, $nth_table = 1, $row_selector = 'tr', $header_row = TRUE)
{
$data = array();
$columns = array();
Expand All @@ -42,6 +78,13 @@ public function extract($table_selector, $nth_table = 1, $row_selector = 'tr',
$html = str_get_dom($this->html);
$table = $html($table_selector, $nth_table-1);

if(empty($table))
{
return FALSE;
//print $this->html;
//exit;
}

foreach($table($row_selector) as $row)
{
$item = array();
Expand Down Expand Up @@ -89,8 +132,11 @@ public function extract($table_selector, $nth_table = 1, $row_selector = 'tr',
}
$col_count++;
}

$data[]= $item;

if(!empty($item))
{
$data[]= $item;
}
}

return $data;
Expand Down

0 comments on commit f13ad51

Please sign in to comment.