Example #1
0
 public function processContent()
 {
     $body = $this->response->getBody();
     $domDocument = new Query($body);
     $limit = 5;
     foreach ($domDocument->execute('ul.prod_grd.three_per_row.prod_lst_square_ic li a.lst_a') as $key) {
         if (--$limit <= 0) {
             //break;
         }
         $href = $key->getAttribute('href');
         if (!parse_url($href, PHP_URL_HOST)) {
             $urlHost = parse_url($this->url, PHP_URL_HOST);
             $urlScheme = parse_url($this->url, PHP_URL_SCHEME) . '://';
             $href = $urlScheme . $urlHost . $href;
         }
         $task = new \Net_Gearman_Task('parse', array('arg' => array('url' => $href, 'file' => $this->fileName)), null, \Net_Gearman_Task::JOB_NORMAL);
         $task->attachCallback($this->getTaskFinishedCallback());
         $this->set->addTask($task);
     }
     if ($this->set->count() > 0) {
         $filename = $this->config->getSystemConfig()->getParseDir() . $this->fileName;
         if (file_exists($filename)) {
             rename($filename, $this->config->getSystemConfig()->getParseDir() . basename($this->fileName, '.csv') . '_toupdate.csv');
         }
         $this->set->attachCallback($this->getJobFinishedCallback());
         Logger::addMessage('Jobs pushed to server: ' . $this->set->count());
         $this->jobTotal = $this->set->count();
         $this->client->runSet($this->set);
     }
 }
Example #2
0
 /**
  * TODO: fix issue with single files in torrent
  * @param unknown $torrentId
  * @return multitype:multitype:NULL Ambigous <unknown>
  */
 private function getFileListing($data)
 {
     $dom = new Query($data);
     $results = $dom->execute('#torrent_files tr');
     $row = array();
     foreach ($results as $parentElement) {
         if ($parentElement->hasAttribute('class') && $parentElement->getAttribute('class') == 'innerFolder') {
             continue;
         }
         $newHTML = $this->nodeToHTML($parentElement);
         $subDom = new Query($newHTML);
         $subResults = $subDom->execute('td');
         $parts = array();
         foreach ($subResults as $subResult) {
             foreach ($subResult->childNodes as $childNode) {
                 $tmpHTML = str_replace(array("\t", "\n"), '', trim($this->nodeToHTML($childNode)));
                 if ($tmpHTML || $tmpHTML === '0') {
                     $parts[] = $tmpHTML;
                 }
             }
         }
         if (count($parts)) {
             $row[] = $parts;
         }
     }
     $output = array();
     foreach ($row as $file) {
         $output[] = array('filename' => $file[2], 'size' => $this->cleanString($file[3] . ' ' . $file[4]));
     }
     return $output;
 }
Example #3
0
 /**
  * Render a dropdown menu
  *
  * @param  string|\SpiffyNavigation\Container|null $container
  * @param  array                                   $options
  * @return string
  */
 public function renderDropDownMenu($container = null, array $options = array())
 {
     $menu = $this->getNavigationMenu()->renderMenu($container, $options);
     $query = new Query($menu, strtolower(mb_detect_encoding($menu)));
     $uls = $query->execute('li>ul');
     /** @var \DOMElement $ul */
     foreach ($uls as $key => $ul) {
         $caret = $uls->getDocument()->createDocumentFragment();
         $caret->appendXML('<b class="caret" />');
         $index = $key + 1;
         $this->addCss('dropdown-menu', $ul);
         $ul->setAttribute('role', 'menu');
         $ul->setAttribute('aria-labelledby', "drop{$index}");
         $li = $ul->parentNode;
         $this->addCss('dropdown', $li);
         $a = $li->firstChild;
         $this->addCss('dropdown-toggle', $a);
         $a->setAttribute('role', 'button');
         $a->setAttribute('data-toggle', 'dropdown');
         $a->setAttribute('href', '#');
         $a->setAttribute('id', "drop{$index}");
         $a->appendChild($caret);
     }
     return preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\\s*~i', '', $uls->getDocument()->saveHTML());
 }
 public function getEBookContentAction()
 {
     header('Access-Control-Allow-Origin: *');
     header('Content-Encoding: plain');
     $id = $_GET['id'];
     if (!isset($id) && $id == "") {
         exit;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "http://www.uus8.org/" . $id . "/");
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $output = curl_exec($ch);
     curl_close($ch);
     //echo $output;
     $dom = new Query($output);
     $results = $dom->execute('div#youli2 li a');
     $rs = array();
     //echo count($results);
     foreach ($results as $result) {
         array_push($rs, array("title" => $result->nodeValue, "id" => $id . "/" . $result->getAttribute("href")));
     }
     //$output=mb_convert_encoding($output, "utf-8", "gb2312");//解析完后再转码,要不然,解析不对。
     echo Json::encode($rs);
     exit;
 }
Example #5
0
 function setPostRut($ruts)
 {
     foreach ($ruts as $rut) {
         $busqueda[] = explode('-', $rut[0]);
     }
     echo '<pre>';
     print_r($busqueda);
     echo '</pre>';
     $client = new Client('http://reca.poderjudicial.cl/', array('maxredirects' => 100, 'timeout' => 600, 'keepalive' => true));
     $headers = $client->getRequest()->getHeaders();
     $cookies = new Zend\Http\Cookies($headers);
     $client->setMethod('GET');
     $response = $client->send();
     $client->setUri('http://reca.poderjudicial.cl/RECAWEB/AtPublicoViewAccion.do?tipoMenuATP=1');
     $cookies->addCookiesFromResponse($response, $client->getUri());
     $response = $client->send();
     $client->setUri("http://reca.poderjudicial.cl/RECAWEB/AtPublicoDAction.do");
     foreach ($busqueda as $rut) {
         $parametros = array('actionViewBusqueda' => '2', 'FLG_Busqueda' => '2', 'FLG_User_Valid' => '0', 'TIP_Lengueta' => 'tdDos', 'COD_Competencia' => 'C', 'tribunal_aux' => '-1', 'username_aux' => '', 'password_aux' => '', 'aux_codlibro' => '', 'aux_rolinterno' => '', 'aux_eracausa' => '', 'aux_codcorte' => '', 'RUT_Cod_Competencia' => 'C', 'RUT_Rut' => $rut[0], 'RUT_Rut_Db' => $rut[1], 'RIT_Cod_Competencia' => '0', 'RIT_Tip_Causa' => '0', 'RIT_Rol_Interno' => '', 'RIT_Era_Causa' => '', 'corte_Cod_Tribunal' => '-1', 'corte_Cod_Libro' => '0', 'corte_Rol_Interno' => '', 'corte_Era_Causa' => '', 'OPC_Cod_Corte' => '-1', 'OPC_Cod_Tribunal' => '-1', 'username' => '', 'password' => '');
         $client->setParameterPost($parametros);
         echo '<pre>';
         print_r($parametros);
         echo '</pre>';
         $response = $client->setMethod('POST')->send();
         $data = $response->getContent();
         echo '<pre>';
         print_r($response->getContent());
         echo '</pre>';
         die;
         $rut = $rut[0] . '-' . $rut[1];
         $dom = new Query($data);
         $resultados = $dom->execute('#divRecursos tr');
         $rols = $this->busquedaRut($resultados, $rut);
     }
 }
 /**
  * Parses a HTML string and turns it into array
  *
  * @param $html
  * @return array
  */
 public function parse($html)
 {
     $data = array();
     $dom = new Query($html);
     $results = $dom->execute('.valor');
     foreach ($results as $key => $result) {
         $data[$this->dataIndex[$key]] = trim($result->nodeValue);
     }
     return $data;
 }
Example #7
0
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['o:source'])) {
         $errorStore->addError('o:source', 'No OEmbed URL specified');
         return;
     }
     $config = $this->getServiceLocator()->get('Config');
     $whitelist = $config['oembed']['whitelist'];
     $whitelisted = false;
     foreach ($whitelist as $regex) {
         if (preg_match($regex, $data['o:source']) === 1) {
             $whitelisted = true;
             break;
         }
     }
     if (!$whitelisted) {
         $errorStore->addError('o:source', 'Invalid OEmbed URL');
         return;
     }
     $source = $data['o:source'];
     $response = $this->makeRequest($source, 'OEmbed URL', $errorStore);
     if (!$response) {
         return;
     }
     $document = $response->getBody();
     $dom = new Query($document);
     $oEmbedLinks = $dom->queryXpath('//link[@rel="alternate" or @rel="alternative"][@type="application/json+oembed"]');
     if (!count($oEmbedLinks)) {
         $errorStore->addError('o:source', 'No OEmbed links were found at the given URI');
         return;
     }
     $oEmbedLink = $oEmbedLinks[0];
     $linkResponse = $this->makeRequest($oEmbedLink->getAttribute('href'), 'OEmbed link URL', $errorStore);
     if (!$linkResponse) {
         return;
     }
     $mediaData = json_decode($linkResponse->getBody(), true);
     if (!$mediaData) {
         $errorStore->addError('o:source', 'Error decoding OEmbed JSON');
         return;
     }
     if (isset($mediaData['thumbnail_url'])) {
         $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
         $file = $this->getServiceLocator()->get('Omeka\\File');
         $this->downloadFile($mediaData['thumbnail_url'], $file->getTempPath());
         $hasThumbnails = $fileManager->storeThumbnails($file);
         if ($hasThumbnails) {
             $media->setFilename($file->getStorageName());
             $media->setHasThumbnails(true);
         }
     }
     $media->setData($mediaData);
     $media->setSource($source);
 }
 public function testGetSectionHtml()
 {
     $scraping = new Scraping();
     $response = $scraping->fetch('31.804.115-0002-43');
     $dom = new Query($response);
     $secao = $dom->execute('td.secao');
     // #fix
     $scraping = new Scraping();
     $arr = $scraping->getSectionHtml($secao);
     $this->assertEquals(count($arr), 3);
 }
 /**
  * Set search results from DOM Client.
  *
  * @param string $search value from users search text
  *
  * @return boolean
  */
 private function setQueryDom($search)
 {
     $client = new Client($search);
     $result = $client->send();
     $body = $result->getBody();
     $dom = new Query($body);
     $results = $dom->execute(self::DOM_CONTENT);
     $count = count($results);
     foreach ($results as $key => $result) {
         $resultText = preg_replace('/^[ \\t]*[\\r\\n]+/m', '', $result->textContent);
         array_push($this->searchResults, $resultText);
     }
     if (empty($this->searchResults)) {
         return false;
     }
     return true;
 }
Example #10
0
 public function testCheckbox()
 {
     // Resolução de Scripts
     $resolver = new TemplateMapResolver(['balance/configs/modules' => './module/Balance/view/balance/configs/modules.phtml', 'layout/page-header' => './module/Balance/view/layout/page-header.phtml']);
     // Renderização
     $renderer = (new PhpRenderer())->setResolver($resolver);
     // Dependências de Plugins
     $manager = $renderer->getHelperPluginManager();
     // Caminho Base
     $manager->get('BasePath')->setBasePath('/');
     // URL
     $match = $this->getMockBuilder('Zend\\Mvc\\Router\\RouteMatch')->disableOriginalConstructor()->getMock();
     $match->method('getMatchedRouteName')->will($this->returnValue('default'));
     // Configurações
     $manager->get('Url')->setRouter($this->getMock('Zend\\Mvc\\Router\\RouteStackInterface'))->setRouteMatch($match);
     // Camada de Visualização
     $view = (new ViewModel())->setTemplate('balance/configs/modules');
     // Variáveis
     $view->setVariable('elements', [['name' => 'Testing Module A', 'identifier' => 'ModuleA', 'enabled' => false, 'description' => 'Description of Module A'], ['name' => 'Testing Module B', 'identifier' => 'ModuleB', 'enabled' => true, 'description' => 'Description of Module B']]);
     // Renderização
     $content = $renderer->render($view);
     // Execução
     $query = new Query($content);
     // Captura
     $elements = $query->execute('#form-modules .panel .panel-heading input[type="checkbox"]');
     // Verificações
     $this->assertCount(3, $elements);
     $element = $elements->current();
     $this->assertEquals('Balance', $element->getAttribute('value'));
     $this->assertTrue($element->hasAttribute('checked'));
     $this->assertTrue($element->hasAttribute('disabled'));
     $elements->next();
     $element = $elements->current();
     $this->assertEquals('ModuleA', $element->getAttribute('value'));
     $this->assertFalse($element->hasAttribute('checked'));
     $this->assertFalse($element->hasAttribute('disabled'));
     $elements->next();
     $element = $elements->current();
     $this->assertEquals('ModuleB', $element->getAttribute('value'));
     $this->assertTrue($element->hasAttribute('checked'));
     $this->assertFalse($element->hasAttribute('disabled'));
 }
 public function filter($html)
 {
     $baseUri = new Http($this->uri);
     $dom = new Query($html);
     $results = $dom->execute('*[@href],*[@src]');
     foreach ($results as $result) {
         $attributeMap = $result->attributes;
         foreach ($attributeMap as $attribute) {
             $name = $attribute->name;
             if ($name == 'href' || $name == 'src') {
                 $value = $result->getAttribute($name);
                 $uri = new Http($value);
                 $h = $uri->resolve($baseUri);
                 $result->setAttribute($name, $h);
             }
         }
     }
     $document = $results->getDocument();
     $documentHTML = $document->saveHTML();
     return $documentHTML;
 }
Example #12
0
 /**
  * Tries discover the given URL and set $_feedUrl and $_feedFormat
  * returns FALSE if no oembed data
  *
  * @param string|false $url
  */
 private function discover($url)
 {
     static $paths = array(Oembed::FEED_FORMAT_JSON => '//link[@href][@type=\'application/json+oembed\']', Oembed::FEED_FORMAT_XML => '//link[@href][@type=\'text/xml+oembed\']');
     $this->_feedUrl = false;
     try {
         $httpClient = $this->getServiceLocator()->get('Zend\\Http\\Client');
         $httpResponse = $httpClient->setUri($url)->send();
         if ($httpResponse && $httpResponse->isSuccess()) {
             $query = new Query($httpResponse->getBody());
             foreach ($paths as $format => $path) {
                 foreach ($query->queryXpath($path) as $node) {
                     $this->_feedFormat = $format;
                     $this->_feedUrl = $node->getAttribute('href');
                     return;
                 }
             }
         }
     } catch (\Exception $ex) {
         //do nothing
     }
 }
 public function getGrocceryJsonData()
 {
     $result = $this->getNewResponse('');
     // content of the web
     $body = $result->getBody();
     $dom = new Query($body);
     // get div with class="gridItem" and h3 a 's NodeList
     $contents = $dom->execute('.gridItem');
     $content = '';
     $grocceryProductArray = array();
     foreach ($contents as $key => $r) {
         // per h3 NodeList, has element with tagName = 'a'
         // DOMElement get Element with tagName = 'a'
         $helement = $r->getElementsByTagName("h3")->item(0);
         $aelement = $helement->getElementsByTagName("a")->item(0);
         if ($aelement->hasAttributes()) {
             // get a tag link for the item details and make a new call for description
             $descriptionResult = $this->getNewResponse($aelement->getAttributeNode('href')->nodeValue);
             $array['title'] = trim($aelement->textContent);
             $descriptionBody = $descriptionResult->getBody();
             $descdom = new Query($descriptionBody);
             // get div with class="productText"
             $desccontents = $descdom->execute('div .productText');
             $kb = (int) (mb_strlen($descriptionBody, 'UTF-8') / 1024);
             $array['size'] = $kb . 'kb';
             foreach ($desccontents as $node => $value) {
                 $hpdelement = $value->getElementsByTagName("p")->item(0);
                 $array['description'] = trim($hpdelement->textContent);
             }
         }
         $priceElement = $this->getElementByClass($r, 'div', 'pricing', $offset = 0);
         $pelement = $priceElement->getElementsByTagName("p")->item(0);
         $array['price'] = $this->parsePrice(trim($pelement->textContent));
         $grocceryProductArray['results'][] = $array;
     }
     // sum the prices to get total
     $grocceryProductArray['total'] = $this->getProductsPriceTotal($grocceryProductArray);
     return \Zend\Json\Json::encode($grocceryProductArray);
 }
Example #14
0
 public function spider($cnpj = null)
 {
     $arr_final = [];
     if ($this->validate_cnpj($cnpj) == false) {
         return ['error' => true, 'message' => 'Numero de CNPJ incorreto.'];
     }
     try {
         $response = $this->fetch($cnpj);
         $dom = new Query($response);
         $results = $dom->execute('table.resultado');
         // #seed1
         $secao = $dom->execute('td.secao');
         // #seed2
         $tables = $dom->execute('table.resultado table');
         // #seed3
         if (count($results) == 1 && count($secao) == 3) {
             $titulos = $dom->execute('td.titulo');
             $valores = $dom->execute('td.valor');
             $scraping = new Scraping();
             $arr_tt = $scraping->getSectionHtml($titulos, ['formatter' => 'l', 'special' => true, 'sanitize' => true]);
             $arr_vl = $scraping->getSectionHtml($valores, ['formatter' => 'l', 'special' => false, 'sanitize' => false]);
             if (count($arr_vl) == 18) {
                 unset($arr_vl[count($arr_vl) - 1]);
                 // #fix
             }
             if (count($arr_tt) == count($arr_vl)) {
                 $arr_final = array_combine($arr_tt, $arr_vl);
                 return ['error' => false, 'message' => 'Dados recuperados com sucesso', 'json' => $arr_final];
             }
         } else {
             return ['error' => true, 'message' => $cnpj . ' não existente em nossa base de dados'];
         }
     } catch (\Exception $e) {
         return $e->getMessage();
     }
     return $arr_final;
 }
Example #15
0
 /**
  * Execute a DOM/XPath query
  *
  * @param  string $path
  * @param  boolean $useXpath
  * @return array
  */
 private function query($path, $useXpath = false)
 {
     $response = $this->getResponse();
     $dom = new Dom\Query($response->getContent());
     if ($useXpath) {
         $dom->registerXpathNamespaces($this->xpathNamespaces);
         return $dom->queryXpath($path);
     }
     return $dom->execute($path);
 }
Example #16
0
 /**
  * Use the supplied CSS selector to query the HTML.  Returns the results
  * as a \Zend\Dom\NodeList, which can be iterated over to inspect the
  * resulting DOMElement objects as needed.
  *
  * @param string $selector
  * @param string $html
  * @return \Zend\Dom\NodeList
  */
 public function queryDom($selector, $html)
 {
     $query = new DomQuery($html);
     return $query->execute($selector);
 }
 public function getXSTBAction()
 {
     header('Access-Control-Allow-Origin: *');
     header('Content-Encoding: plain');
     $sdate = $_REQUEST['sdate'];
     if (!isset($sdate) || $sdate == "") {
         exit;
     }
     $cclass = $_REQUEST['cclass'];
     if (!isset($cclass) || $cclass == "") {
         exit;
     }
     //2014/1/1-2014/4/31
     $sdate = urldecode($sdate);
     $arrdate = explode("-", $sdate);
     $arrdate2 = explode("/", $arrdate[0]);
     $sdatey = $arrdate2[0];
     $sdatem = $arrdate2[1];
     $sdated = $arrdate2[2];
     $arrdate2 = explode("/", $arrdate[1]);
     $edatey = $arrdate2[0];
     $edatem = $arrdate2[1];
     $edated = $arrdate2[2];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "http://192.168.4.152:82/cgi-win/web_xstb.exe");
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, 1);
     //$curlPost="title=&sdatey=2014&sdatem=1&sdated=1&author=&edatey=2014&edatem=4&edated=24&publisher=&rowcount=500&class=tu&query=检索";
     $curlPost = "title=&sdatey=" . $sdatey . "&sdatem=" . $sdatem . "&sdated=" . $sdated . "&author=&edatey=" . $edatey . "&edatem=" . $edatem . "&edated=" . $edated . "&publisher=&rowcount=500&class=" . $cclass . "&query=%BC%EC%CB%F7";
     //echo $curlPost;
     curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
     $output = curl_exec($ch);
     curl_close($ch);
     //$output=mb_convert_encoding($output, "utf-8", "gb2312");
     $rs = array();
     $dom = new Query('<meta http-equiv="Content-Type" content="text/html;charset=gb2312">' . $output);
     $results = $dom->execute('table');
     foreach ($results as $result) {
         $tr = $result->getElementsByTagName('tr');
         for ($c = 1; $c < $tr->length; $c++) {
             $cols = $tr->item($c)->getElementsByTagName('td');
             $classno = $cols->item(0)->textContent;
             $title = $cols->item(1)->textContent;
             $href = $cols->item(1)->firstChild->getAttribute("href");
             $href = substr($href, strpos($href, '?') + 1);
             array_push($rs, array("title" => $title, "authors" => "", "year" => "", "classno" => $classno, "href" => $href));
         }
     }
     //echo $output;
     echo Json::encode($rs);
     exit;
 }
Example #18
0
 /**
  * @group ZF-3938
  */
 public function testAllowsSpecifyingEncodingAtConstruction()
 {
     $doc = new Query($this->getHtml(), 'iso-8859-1');
     $this->assertEquals('iso-8859-1', $doc->getEncoding());
 }
Example #19
0
 public function testConstructorShouldAcceptDocumentString()
 {
     $html = $this->getHtml();
     $query = new Query($html);
     $this->assertSame($html, $query->getDocument());
 }
Example #20
0
 public function getCountryofOrigin(Query $dom, $_feed_dom = null)
 {
     if ($_feed_dom == null) {
         $_feed_dom = 'div.detail div.main article div.like a span';
     }
     //'li.country';
     $_CountryofOrigin = array();
     $get_CountryofOrigin = $dom->execute($_feed_dom);
     if (count($get_CountryofOrigin) > 0) {
         foreach ($get_CountryofOrigin as $key => $_pro) {
             $str = @trim($_pro->textContent);
             $_CountryofOrigin[] = $str;
         }
     } else {
         $this->setPropertyCountryofOrigin("loi khi lay ProductDetails");
     }
     $this->setPropertyCountryofOrigin($_CountryofOrigin);
 }
Example #21
0
 $client->setParameterPost(array('TIP_Consulta' => '3', 'TIP_Lengueta' => 'tdCuatro', 'SeleccionL' => '0', 'TIP_Causa' => '', 'ROL_Causa' => '', 'ERA_Causa' => '', 'RUC_Era' => '', 'RUC_Tribunal' => '3', 'RUC_Numero' => '', 'RUC_Dv' => '', 'FEC_Desde' => '20/08/2015', 'FEC_Hasta' => '20/08/2015', 'SEL_Litigantes' => '0', 'RUT_Consulta' => '', 'RUT_DvConsulta' => '', 'NOM_Consulta' => $demandado['nombre'], 'APE_Paterno' => $demandado['apPaterno'], 'APE_Materno' => $demandado['apMaterno'], 'COD_Tribunal' => '0', 'irAccionAtPublico' => 'Consulta'));
 $response = $client->setMethod('POST')->send();
 if ($response->isSuccess()) {
     $data = $response->getContent();
     $dom = new Query($data);
     $results = $dom->execute('#contentCellsAddTabla tr');
     $informacionCausas = $scrap->getCausas($results);
     echo '<pre>Se encontraron: ' . count($informacionCausas) . ' causas</pre>';
     $postCausas = $scrap->setPostCausas($informacionCausas);
     $client->setUri("http://civil.poderjudicial.cl/CIVILPORWEB/ConsultaDetalleAtPublicoAccion.do?");
     $cookies->addCookiesFromResponse($response, $client->getUri());
     foreach ($postCausas as $post) {
         $client->setParameterPost(array("TIP_Consulta" => $post['TIP_Consulta'], "TIP_Cuaderno" => $post['TIP_Cuaderno'], "CRR_IdCuaderno" => $post['CRR_IdCuaderno'], "ROL_Causa" => $post['ROL_Causa'], "TIP_Causa" => $post['TIP_Causa'], "ERA_Causa" => $post['ERA_Causa'], "COD_Tribunal" => $post['COD_Tribunal'], "TIP_Informe" => $post['TIP_Informe'] . "&"));
         $response = $client->setMethod('POST')->send();
         $data = $response->getContent();
         $dom = new Query($data);
         $detalleCausa = $dom->execute('tr');
         $rol = $post['TIP_Causa'] . '-' . $post['ROL_Causa'] . '-' . $post['ERA_Causa'];
         $arr_detalles = $scrap->infoCausas($detalleCausa, $rol);
         $cuadernos = $dom->execute("#TablaCuadernos");
         $cuaderno = $scrap->getNombreCuadernos($cuadernos);
         $litigantes = $dom->execute("#Litigantes table tr");
         $arr_litigantes = $scrap->getLitigantes($litigantes, $rol, $demandado['rut'], $cuaderno);
         $tribunal = $arr_detalles['tribunal'];
         $cuadernos = $dom->execute("#TablaCuadernos");
         $nombreCuaderno = $scrap->getNombreCuadernos($cuadernos);
         $historias = $dom->execute("#Historia tr");
         $arr_historias = $scrap->getHistorias($historias, $rol, $rut, $tribunal, $nombreCuaderno);
         //echo '<pre>Rut Demandado:'.$rut.'</pre>';
         foreach ($arr_litigantes as $ar) {
             echo '<pre>' . $ar['rut'] . '</pre>';
Example #22
0
 public function getProductPromotion(Query $dom, $_feed_dom = null)
 {
     if ($_feed_dom == null) {
         $_feed_dom = 'div.items article div.ico';
     }
     /* -- Product Promotion --- */
     $_ProductPromotion = array();
     $get_Product_Promotion = $dom->execute($_feed_dom);
     // $get_Product_Img : anh cua san pham //img.grocery-image-placeholder
     /* var_dump ( count ( $get_Product_Promotion ) ); die (); */
     if (count($get_Product_Promotion) > 0) {
         foreach ($get_Product_Promotion as $key => $_pro) {
             // echo "<pre>"; print_r ( $_pro->textContent );
             $str = @trim($_pro->textContent);
             // $result = $str_replace(" ", "", $_pro->textContent);
             $_ProductPromotion[] = $str;
         }
     } else {
         $this->setPropertyProductPromotion("loi khi lay product Promotion");
     }
     $this->setPropertyProductPromotion($_ProductPromotion);
 }
 function setBusqueda($posts)
 {
     $client = $this->setClient();
     $headers = $client->getRequest()->getHeaders();
     $cookies = new Zend\Http\Cookies($headers);
     $client->setMethod('GET');
     $response = $client->send();
     $uri = 'http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoViewAccion.do?tipoMenuATP=1';
     $client->setUri($uri);
     $cookies->addCookiesFromResponse($response, $client->getUri());
     $response = $client->send();
     foreach ($posts as $post) {
         echo '<pre>';
         print_r("Se estan consultado las causas para: " . $post['NOM_Consulta'] . " " . $post['APE_Paterno'] . " " . $post['APE_Materno']);
         echo '</pre>';
         $rut_buscado = array_pop($post);
         $client->setUri('http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do');
         $cookies->addCookiesFromResponse($response, $client->getUri());
         $client->setParameterPost($post);
         $response = $client->setMethod('POST')->send();
         if ($response->isOk()) {
             $data = $response->getContent();
             $dom = new Query($data);
             $results = $dom->execute('#contentCellsAddTabla tr');
             $informacionCausas = $this->getCausas($results);
             echo '<pre> Se han encontrado: ' . count($informacionCausas) . ' causas';
             if (count($informacionCausas) > 0) {
                 $postCausas = $this->setPostCausas($informacionCausas);
                 $client->setUri("http://civil.poderjudicial.cl/CIVILPORWEB/ConsultaDetalleAtPublicoAccion.do?");
                 $cookies->addCookiesFromResponse($response, $client->getUri());
                 foreach ($postCausas as $causa) {
                     $client->setParameterPost($causa);
                     $response = $client->setMethod('POST')->send();
                     if ($response->isOk()) {
                         $data = $response->getContent();
                         $dom = new Query($data);
                         $detalleCausa = $dom->execute('tr');
                         $rol = $causa['TIP_Causa'] . '-' . $causa['ROL_Causa'] . '-' . $causa['ERA_Causa'];
                         $arr_detalles = $this->infoCausas($detalleCausa, $rol, $rut_buscado);
                         $cuadernos = $dom->execute("#TablaCuadernos .comboBox option");
                         $cuadernos = $dom->execute("#TablaCuadernos .comboBox option");
                         $contador = 0;
                         foreach ($cuadernos as $cuaderno) {
                             $arr_cuadernos[$contador]['nombre'] = $cuaderno->textContent;
                             $arr_cuadernos[$contador]['id'] = $cuaderno->attributes->getNamedItem('value')->textContent;
                             $contador++;
                         }
                         $litigantes = $dom->execute("#Litigantes table tr");
                         $arr_litigantes = $this->getLitigantes($litigantes, $rol, $rut_buscado, $arr_cuadernos[0]['nombre']);
                         $tribunal = $arr_detalles['tribunal'];
                         $historias = $dom->execute("#Historia tr");
                         $arr_historias = $this->getHistorias($historias, $rol, $rut_buscado, $tribunal, $arr_cuadernos[0]['nombre']);
                         foreach ($arr_litigantes as $ar) {
                             if (strpos($ar['rut'], $rut_buscado)) {
                                 echo "<pre> Entr igual: " . $arr_detalles['estado_proceso'] . "</pre>";
                                 $connect = new Conexion();
                                 $connect->insertCausa($arr_detalles, $rut_buscado);
                                 $connect->insertCausaHistoria($arr_historias);
                             }
                         }
                         if (count($cuadernos) > 1) {
                             $documento = $dom->getDocument();
                             preg_match_all("/(TIP_Cuaderno.value.*')/", $documento, $tips);
                             preg_match_all("/(CRR_IdCuaderno.value.*)/", $documento, $crrids);
                             $arr_tips_cuadernos = $tips[0];
                             $arr_crr_cuadernos = $crrids[0];
                             $contador = 0;
                             for ($i = 1; $i < count($cuadernos); $i++) {
                                 $postCuaderno[$contador]['tip'] = str_replace("TIP_Cuaderno.value   = '", "", $arr_tips_cuadernos[$i]);
                                 $postCuaderno[$contador]['tip'] = str_replace("'", "", $postCuaderno[$contador]['tip']);
                                 $postCuaderno[$contador]['crr'] = str_replace("CRR_IdCuaderno.value = '", "", $arr_crr_cuadernos[$i]);
                                 $postCuaderno[$contador]['crr'] = str_replace("';", "", $postCuaderno[$contador]['crr']);
                                 $postCuaderno[$contador]['crr'] = trim(rtrim($postCuaderno[$contador]['crr'], " "));
                                 $postCuaderno[$contador]['gls'] = $arr_cuadernos[$i]['nombre'];
                                 $postCuaderno[$contador]['tip_causa'] = $causa['TIP_Causa'];
                                 $postCuaderno[$contador]['rol_causa'] = $causa['ROL_Causa'];
                                 $postCuaderno[$contador]['era_causa'] = $causa['ERA_Causa'];
                                 $postCuaderno[$contador]['cod_tribunal'] = $causa['COD_Tribunal'];
                                 $contador++;
                             }
                             foreach ($postCuaderno as $cuaderno) {
                                 $post_parameters = array('TIP_Causa' => $cuaderno['tip_causa'], 'ROL_Causa' => $cuaderno['rol_causa'], 'ERA_Causa' => $cuaderno['era_causa'], 'COD_Tribunal' => $cuaderno['cod_tribunal'], 'TIP_Cuaderno' => $cuaderno['tip'], 'GLS_Cuaderno' => $cuaderno['gls'], 'CRR_IdCuaderno' => $cuaderno['crr'], 'TIP_Informe' => '1', 'FLG_Caratula' => '0', 'TIP_Cargo' => '2', 'COD_Corte' => '98', 'FLG_ImpresionTribunal' => '1', 'CRR_Cuaderno' => $cuaderno['crr'], 'irAccionAtPublico' => 'Ir a Cuaderno', 'FLG_Vuelta' => 'null');
                                 $client->setUri("http://civil.poderjudicial.cl/CIVILPORWEB/AtPublicoDAction.do");
                                 $cookies->addCookiesFromResponse($response, $client->getUri());
                                 $client->setParameterPost($post_parameters);
                                 $response = $client->setMethod('POST')->send();
                                 $data = $response->getContent();
                                 $dom = new Query($data);
                                 $cuaderno = $cuaderno['gls'];
                                 $tribunal = $arr_detalles['tribunal'];
                                 $litigantes = $dom->execute("#Litigantes table tr");
                                 $arr_litigantes = $this->getLitigantes($litigantes, $rol, $rut_buscado, $arr_cuadernos[0]['nombre']);
                                 $historias = $dom->execute("#Historia tr");
                                 $arr_historias = $this->getHistorias($historias, $rol, $rut_buscado, $tribunal, $cuaderno);
                                 foreach ($arr_litigantes as $ar) {
                                     if (strpos($ar['rut'], $rut_buscado) !== false) {
                                         $connect = new Conexion();
                                         $connect->insertCausaHistoria($arr_historias);
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 echo '<pre>';
                 print_r("Ha ocurrido un problema con la conexión, por favor intentelo mas tarde");
                 echo '<pre>';
             }
         }
     }
 }
Example #24
0
 /**
  * リンク元にアクセスして自サイトへのアドレスが存在するかのチェック
  * @return boolean
  */
 private function is_not_valid_referer()
 {
     static $condition;
     // 本来は正規化されたアドレスでチェックするべきだろうが、
     // めんどうだからスクリプトのアドレスを含むかでチェック
     // global $vars;
     // $script = get_page_absuri(isset($vars['page']) ? $vars['page'] : '');
     if (empty($condition)) {
         $parse_url = Router::get_script_uri();
         $condition = $parse_url['host'] . $parse_url['path'];
         // QueryStringは評価しない。
     }
     $response = ClientStatic::get($this->referer);
     if (!$response->isSuccess()) {
         return true;
     }
     $dom = new Query($response->getBody());
     $results = $dom->execute('a[href=^"' . $condition . '"]');
     foreach ($results as $element) {
         // hrefがhttpから始まるaタグを走査
         if (preg_match('/' . $condition . '/i', $element->href) !== 0) {
             return false;
             break;
         }
     }
     return true;
 }
 public function single_pare_dom($output, $k, $_url_tmp)
 {
     $dom = new Query($output);
     /* --- Product Name and Product URL-->getdetail -- */
     $ProductName = array();
     $Product_Url = array();
     $get_Product_Name = $dom->execute($this->dom_Name[$k]);
     if (count($get_Product_Name) > 0) {
         foreach ($get_Product_Name as $key => $r) {
             $aelement = $r->getElementsByTagName("a")->item(0);
             if ($aelement->hasAttributes()) {
                 $ProductName[] = $aelement->textContent;
                 $Product_Url[] = $aelement->getAttributeNode('href')->nodeValue;
             }
         }
     } else {
         echo "loi khi lay product name";
     }
     /* -- Product Promotion --- */
     $ProductPromotion = array();
     $get_Product_Promotion = $dom->execute($this->dom_Promotion[$k]);
     if (count($get_Product_Promotion) > 0) {
         foreach ($get_Product_Promotion as $key => $_pro) {
             $ProductPromotion[] = $_pro->textContent;
         }
     } else {
         echo "loi khi lay product Promotion";
     }
     /* --- Get Product Price  -- */
     $ProductPrice = array();
     $Product_Price_older = array();
     $get_Product_Price = $dom->execute($this->dom_Price[$k]);
     if (count($get_Product_Price) > 0) {
         foreach ($get_Product_Price as $key => $_Price) {
             //echo "<pre>"; print_r ( $_Price->textContent);
             $ProductPrice[] = @trim($_Price->textContent);
         }
     } else {
         echo "loi khi lay product Price";
     }
     /* -- Product Img --- */
     $ProductImg = array();
     $get_Product_Img = $dom->execute($this->dom_Img[$k]);
     if (count($get_Product_Img) > 0) {
         foreach ($get_Product_Img as $key => $_img) {
             $ProductImg[] = $_img->getAttributeNode('data-replace')->nodeValue;
         }
     } else {
         echo "loi khi lay product img";
     }
     //save data cache
     // Lưu tin đã lấy vào file cache
     $napoje_tmp = array();
     for ($i = 0; $i < @count($ProductName); $i++) {
         $napoje_tmp[$i]['url'] = $_url_tmp;
         $napoje_tmp[$i]['name'] = $ProductName[$i];
         $napoje_tmp[$i]['url_alias'] = $Product_Url[$i];
         $napoje_tmp[$i]['thumbnail'] = $ProductImg[$i];
         $napoje_tmp[$i]['price'] = $ProductPrice[$i];
         $napoje_tmp[$i]['promotion'] = $ProductPromotion[$i];
     }
     return $napoje_tmp;
 }
Example #26
0
 private function getFileListing($torrentId)
 {
     $url = 'http://' . $this->domain . '/ajax_details_filelist.php?id=' . $torrentId;
     $data = $this->retreiveData($url, self::FORMAT_PLAIN);
     $dom = new Query($data);
     $results = $dom->execute('tr');
     $row = array();
     foreach ($results as $parentElement) {
         $newHTML = $this->nodeToHTML($parentElement);
         $subDom = new Query($newHTML);
         $subResults = $subDom->execute('td');
         $parts = array();
         foreach ($subResults as $subResult) {
             foreach ($subResult->childNodes as $childNode) {
                 $tmpHTML = str_replace(array("\t", "\n"), '', trim($this->nodeToHTML($childNode)));
                 if ($tmpHTML || $tmpHTML === '0') {
                     $parts[] = $tmpHTML;
                 }
             }
         }
         if (count($parts)) {
             $row[] = $parts;
         }
     }
     $output = array();
     foreach ($row as $file) {
         $output[] = array('filename' => $file[0], 'size' => $this->convertFileSize($file[1]));
     }
     return $output;
 }
Example #27
0
 /**
  * Add a new subscription
  *
  * @return JsonModel
  */
 public function create($data)
 {
     $username = $this->params()->fromRoute('username');
     $usersTable = $this->getTable('UsersTable');
     $user = $usersTable->getByUsername($username);
     $userFeedsTable = $this->getTable('UserFeedsTable');
     $rssLinkXpath = '//link[@type="application/rss+xml"]';
     $faviconXpath = '//link[@rel="shortcut icon"]';
     $client = new Client($data['url']);
     $client->setEncType(Client::ENC_URLENCODED);
     $client->setMethod(\Zend\Http\Request::METHOD_GET);
     $response = $client->send();
     if ($response->isSuccess()) {
         $html = $response->getBody();
         $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
         $dom = new Query($html);
         $rssUrl = $dom->execute($rssLinkXpath);
         if (!count($rssUrl)) {
             throw new Exception('Rss url not found in the url provided', 404);
         }
         $rssUrl = $rssUrl->current()->getAttribute('href');
         $faviconUrl = $dom->execute($faviconXpath);
         if (count($faviconUrl)) {
             $faviconUrl = $faviconUrl->current()->getAttribute('href');
         } else {
             $faviconUrl = null;
         }
     } else {
         throw new Exception("Website not found", 404);
     }
     $rss = Reader::import($rssUrl);
     return new JsonModel(array('result' => $userFeedsTable->create($user->id, $rssUrl, $rss->getTitle(), $faviconUrl)));
 }
 public function getBJAction()
 {
     header('Access-Control-Allow-Origin: *');
     $output = $this->curlGo("http://www.gxjsxy.cn/tsg/Center.aspx?t=1&c=5");
     $dom = new Query($output);
     $results = $dom->execute('div#ContentsCt1_Content1');
     foreach ($results as $result) {
         $output = $result->ownerDocument->saveXML($result);
     }
     echo $output;
     exit;
 }
 public function curlget($uri, $key)
 {
     $config = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false));
     $client = new \Zend\Http\Client($uri, $config);
     $response = $this->getResponse();
     $response->getHeaders()->addHeaderLine('content-type', 'text/html; charset=UTF-8');
     //set content-type
     $result = $client->send();
     $body = $result->getBody();
     //content of the web
     $dom = new Query($body);
     /* --  $_ProductDetails --- */
     $_ProductDetails;
     $get_ProductDetails = $dom->execute('div.popupDetail div.table div.cell div.tabs div.tab');
     // div.detail div.main section
     if (count($get_ProductDetails) > 0) {
         foreach ($get_ProductDetails as $key => $_pro) {
             //echo "<pre>"; print_r (  $_pro->textContent );
             $str = @trim($_pro->textContent);
             //$result = $str_replace(" ", "", $_pro->textContent);
             $_ProductDetails = $str;
         }
     } else {
         $_ProductDetails = "loi khi lay ProductDetails";
     }
     /*************$_CountryofOrigin***************************/
     $_feed_dom = 'li.country';
     //div.detail div.main article div.like a span
     $_CountryofOrigin;
     $get_CountryofOrigin = $dom->execute($_feed_dom);
     if (count($get_CountryofOrigin) > 0) {
         foreach ($get_CountryofOrigin as $key => $_pro) {
             $str = @trim($_pro->textContent);
             $_CountryofOrigin = $str;
         }
     } else {
         $_CountryofOrigin = "loi khi lay ProductDetails";
     }
     $Data_details = new \stdClass();
     $Data_details->details = $_ProductDetails;
     $Data_details->countryoforigin = $_CountryofOrigin;
     //unset($ch, $options);
     return $Data_details;
 }
Example #30
0
 /**
  * Handle the creation of a new link
  *
  * @param array $data 
  * @return JsonModel
  */
 protected function createLink($data)
 {
     $userLinksTable = $this->getUserLinksTable();
     $filters = $userLinksTable->getInputFilter();
     $filters->setData($data);
     if ($filters->isValid()) {
         $data = $filters->getValues();
         $client = new Client($data['url']);
         $client->setEncType(Client::ENC_URLENCODED);
         $client->setMethod(\Zend\Http\Request::METHOD_GET);
         $response = $client->send();
         if ($response->isSuccess()) {
             $html = $response->getBody();
             $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
             $dom = new Query($html);
             $title = $dom->execute('title')->current()->nodeValue;
             if (!empty($title)) {
                 $filterChain = new FilterChain();
                 $filterChain->attach(new StripTags());
                 $filterChain->attach(new StringTrim());
                 $filterChain->attach(new StripNewLines());
                 $title = $filterChain->filter($title);
             } else {
                 $title = NULL;
             }
             return new JsonModel(array('result' => $userLinksTable->create($data['user_id'], $data['url'], $title)));
         }
     }
     return new JsonModel(array('result' => false, 'errors' => $filters->getMessages()));
 }