Пример #1
0
 /**
  * Extarct values according process
  *
  * @param Diggin_Scraper_Wrapper_SimpleXMLElement $values
  * @param Diggin_Scraper_Process $process
  * @return array|false
  */
 public function extract($values, $process)
 {
     $results = (array) $values->xpath(self::_xpathOrCss2Xpath($process->getExpression()));
     // count($results) === 0 is not found by xpath-node
     // $results[0] === false is not found by attributes
     if (count($results) === 0 or $results[0] === false) {
         return false;
     }
     return $results;
 }
Пример #2
0
 public function __construct(array $config = array())
 {
     parent::__construct($config);
     $process = new Diggin_Scraper_Process();
     $process->setExpression($config['expression']);
     $process->setName('kumo');
     $process->setArrayFlag(isset($config['arrayflag']) ? (bool) $config['arrayflag'] : true);
     $process->setType(isset($config['type']) ? $config['type'] : 'TEXT');
     // use only first filter
     if (isset($config['filters'])) {
         if (($match = $config['filters']['matchpattern']) && ($replace = $config['filters']['replacement'])) {
             require_once 'Zend/Filter/PregReplace.php';
             $pregreplace = new Zend_Filter_PregReplace();
             $pregreplace->setMatchPattern($match);
             $pregreplace->setReplacement($replace);
             $process->setFilters(array($pregreplace));
         }
     }
     $this->scraper = new Diggin_Scraper();
     $this->scraper->process($process);
 }