Esempio n. 1
0
 /**
  * Grabber for finance.i.ua is a bit deeper than a common
  * 
  * @param simple_html_dom_node $cells
  * @param type $tr_idx
  * @param type $td_idx
  * @return type
  * @throws \Exception
  */
 protected function grabTableCell(simple_html_dom_node $cells, $tr_idx, $td_idx)
 {
     $row = $cells->find('tr', $tr_idx);
     if (empty($row)) {
         throw new \LogicException('broken markup: no cells row');
     }
     $cell = $row->find('td', $td_idx);
     if (!empty($cell)) {
         $cell = $cell->first_child();
     }
     if (empty($cell)) {
         throw new \LogicException('broken markup: no cells cell');
     }
     return trim($cell->plaintext);
 }
Esempio n. 2
0
 protected function grabTableCell(simple_html_dom_node $cells, $cell_selector, $cell_idx)
 {
     // get cell
     $cell = $cells->find($cell_selector, $cell_idx);
     if (empty($cell)) {
         throw new \LogicException('broken markup: no cells cell');
     }
     $cell_text = $cell->innertext;
     // clear useless blocks
     $children = $cell->children();
     if (!empty($children)) {
         foreach ($cell->children() as $child) {
             $cell_text = str_replace($child->outertext, '', $cell_text);
         }
     }
     // filter data
     $cell_text = str_replace('грн', '', $cell_text);
     $cell_text = str_replace(',', '.', $cell_text);
     return trim($cell_text);
 }
 /**
  * Grab, check and filter cell in exchanges DOM node
  * Most of banks store exchange values in DOM structures like table
  * This method is covering most of the job
  * 
  * @param simple_html_dom_node $cells
  * @param int $tr_idx
  * @param int $td_idx
  * @param string $tr_selector
  * @param string $td_selector
  * @return string
  * @throws \Exception
  */
 protected function grabTableCell(simple_html_dom_node $cells, $tr_idx, $td_idx, $tr_selector = null, $td_selector = null)
 {
     // reassign empty selectors if any
     $tr_selector = $tr_selector ?: 'tr';
     $td_selector = $td_selector ?: 'td';
     // get row
     $row = $cells->find($tr_selector, $tr_idx);
     if (empty($row)) {
         throw new \LogicException('broken markup: no cells row');
     }
     // get cell
     $cell = $row->find($td_selector, $td_idx);
     if (empty($cell)) {
         throw new \LogicException('broken markup: no cells cell');
     }
     // get data
     $data = $cell->plaintext;
     // filter data
     if (!empty($data)) {
         $data = str_replace(',', '.', $data);
         $data = str_replace([' ', ' '], '', $data);
     }
     // return filtered result
     return $data;
 }