Author: Fabien Potencier (fabien@symfony.com)
Inheritance: extends SplObjectStorage
 protected function setUp()
 {
     $this->client = static::createClient();
     $this->client->followRedirects(true);
     $this->crawler = $this->client->request('GET', self::LOGIN_URL);
     $this->loginForm = $this->crawler->selectButton(self::LOGIN_BUTTON)->form();
 }
Ejemplo n.º 2
0
 public function productAction()
 {
     $client = new Client('http://stroyka.by');
     $request = $client->get('/');
     $request->send();
     $resault = $request->getResponse()->getBody(true);
     $crawler = new Crawler();
     //        $crawler->addHTMLContent($resault);
     //        $res = $request->getResponse()->getH;
     //        var_dump($res);exit();
     //        $text = utf8_decode($resault);
     $crawler = new Crawler($resault);
     $resault = $crawler->filter('ul.b-categories')->html();
     //
     //
     //        $crowler2 = new Crawler($resault);
     //
     //        $resault = $crowler2->filter('span.b-categories__name');
     //
     //        $nodeValues = $crawler->filter('span.b-categories__name')->each(function (Crawler $node, $i) {
     //            return utf8_decode($node->text());
     //        });
     //        var_dump(mb_detect_encoding($nodeValues[0]));exit();
     //        foreach($nodeValues as $nv) {
     //            $category = new Category();
     //            $category->setName($nv);
     //            $this->getDoctrine()->getManager()->persist($category);
     //        }
     //        $this->getDoctrine()->getManager()->flush();
     //        var_dump($nodeValues);
     //        var_dump($resault);
     //        exit;
     return $this->render('AcmeAppBundle:Default:product.html.twig', array('result' => $resault));
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $httpClient = $this->getHttpClientHelper();
     $site_name = $input->getArgument('site-name');
     $version = $input->getArgument('version');
     if ($version) {
         $release_selected = $version;
     } else {
         // Getting Module page header and parse to get module Node
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.getting-releases')) . '</info>');
         // Page for Drupal releases filter by Drupal 8
         $project_release_d8 = 'https://www.drupal.org/node/3060/release?api_version%5B%5D=7234';
         // Parse release module page to get Drupal 8 releases
         try {
             $html = $httpClient->getHtml($project_release_d8);
         } catch (\Exception $e) {
             $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
             return;
         }
         $crawler = new Crawler($html);
         $releases = [];
         foreach ($crawler->filter('span.file a') as $element) {
             if (strpos($element->nodeValue, ".tar.gz") > 0) {
                 $release_name = str_replace('.tar.gz', '', str_replace('drupal-', '', $element->nodeValue));
                 $releases[$release_name] = $element->nodeValue;
             }
         }
         if (empty($releases)) {
             $output->writeln('[+] <error>' . $this->trans('commands.module.site.new.no-releases') . '</error>');
             return;
         }
         // List module releases to enable user to select his favorite release
         $questionHelper = $this->getQuestionHelper();
         $question = new ChoiceQuestion('Please select your favorite release', array_combine(array_keys($releases), array_keys($releases)), 0);
         $release_selected = $questionHelper->ask($input, $output, $question);
     }
     $release_file_path = 'http://ftp.drupal.org/files/projects/drupal-' . $release_selected . '.tar.gz';
     // Destination file to download the release
     $destination = tempnam(sys_get_temp_dir(), 'drupal.') . "tar.gz";
     try {
         // Start the process to download the zip file of release and copy in contrib folter
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.downloading'), $release_selected) . '</info>');
         $httpClient->downloadFile($release_file_path, $destination);
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.extracting'), $release_selected) . '</info>');
         $zippy = Zippy::load();
         $archive = $zippy->open($destination);
         $archive->extract('./');
         try {
             $fs = new Filesystem();
             $fs->rename('./drupal-' . $release_selected, './' . $site_name);
         } catch (IOExceptionInterface $e) {
             $output->writeln('[+] <error>' . sprintf($this->trans('commands.site.new.messages.error-copying'), $e->getPath()) . '</error>');
         }
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.site.new.messages.downloaded'), $release_selected, $site_name) . '</info>');
     } catch (\Exception $e) {
         $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
         return;
     }
     return true;
 }
Ejemplo n.º 4
0
 public function isJoomla()
 {
     $baseUrlJoomla = $this->target;
     $validExtension = preg_match("/^.*\\.(jpg|JPG|gif|GIF|doc|DOC|pdf|PDF)\$/", $this->target, $m);
     if ($validExtension) {
         $baseUrlJoomla = $this->getBaseUrlJoomla();
     }
     $header = new FakeHeaders();
     try {
         $client = new Client(['defaults' => ['headers' => ['User-Agent' => $header->getUserAgent()], 'proxy' => $this->proxy, 'timeout' => 30]]);
         $body = $client->get($baseUrlJoomla)->getBody()->getContents();
         $crawler = new Crawler($body);
         $arrLinksMeta = $crawler->filter('meta');
         foreach ($arrLinksMeta as $keyLinkMeta => $valueLinkMeta) {
             $validJoomlaMeta = preg_match('/Joomla!/', $valueLinkMeta->getAttribute('content'), $m, PREG_OFFSET_CAPTURE);
             if ($validJoomlaMeta) {
                 return true;
             }
         }
         $arrLinksScript = $crawler->filter('script');
         foreach ($arrLinksScript as $keyLinkScript => $valueLinkScript) {
             $validJoomlaScript = preg_match("/(\\/media\\/system\\/js\\/mootools(.js|-core.js))/", $valueLinkScript->getAttribute('src'), $m, PREG_OFFSET_CAPTURE);
             if ($validJoomlaScript) {
                 return true;
             }
         }
     } catch (\Exception $e) {
         return false;
     }
     return false;
 }
Ejemplo n.º 5
0
 public function process()
 {
     $crawler = $this->client->request($this->plan['method'], $this->plan['uri']);
     if (isset($this->plan['selector'])) {
         $selection = $crawler->filter($this->plan['selector']);
     } elseif (isset($this->plan['xpath'])) {
         $selection = $crawler->filterXPath($this->plan['path']);
     }
     if ($this->plan['images']) {
         $images = $selection->filterXPath('//img');
         if (iterator_count($images) > 1) {
             foreach ($images as $image) {
                 $crawler = new Crawler($image);
                 $info = parse_url($this->plan['uri']);
                 $url = $info['scheme'] . '://' . $info['host'] . '/' . $crawler->attr('src');
                 if (strpos($crawler->attr('src'), 'http') === 0) {
                     $url = $info['scheme'] . '://' . $info['host'] . '/' . $this->plan['path'] . $crawler->attr('src');
                 }
                 copy($url, SCRYPHP_STORAGE_PATH_IMG . DIRECTORY_SEPARATOR . substr(strrchr($url, "/"), 1));
             }
         }
     }
     file_put_contents(SCRYPHP_STORAGE_PATH_TXT . DIRECTORY_SEPARATOR . time() . uniqid(time(), true) . '.txt', $selection->text());
     return $selection->text();
 }
Ejemplo n.º 6
0
 /**
  * Scrapes single news item from screenrant
  * 
  * @param  string $url
  * @return string
  */
 public function getSingleFromScreenRant($url)
 {
     $text = '';
     $item = $this->curl($url);
     $crawler = new Crawler($item);
     $html = $crawler->filter('div[itemprop="articleBody"] p')->each(function (Crawler $node, $i) {
         $ht = trim($node->html());
         //filter out unneeded html
         if (strpos($ht, 'contentjumplink')) {
             return false;
         }
         if (strpos($ht, 'type="button"')) {
             return false;
         }
         if (strpos($ht, 'type="hidden"')) {
             return false;
         }
         if (strpos($ht, 'AD BLOCK')) {
             return false;
         }
         if (strpos($ht, 'src=')) {
             preg_match('/.*?<img src="(.*?)"/', $ht, $m);
             if (isset($m[1])) {
                 return "<img src='{$m[1]}' class='img-responsive'/>";
             }
         }
         return '<p>' . preg_replace('/<a.*?>(.*?)<\\/a>/', '$1', $ht) . '</p>';
     });
     return trim(implode('', $html));
 }
Ejemplo n.º 7
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     /** @var $response Response */
     $response = $next($request);
     // Only handle non-redirections and must be a pjax-request
     if (!$response->isRedirection() && $request->pjax()) {
         $crawler = new Crawler($response->getContent());
         // Filter to title (in order to update the browser title bar)
         $response_title = $crawler->filter('head > title');
         // Filter to given container
         $response_container = $crawler->filter($request->header('X-PJAX-CONTAINER'));
         // Container must exist
         if ($response_container->count() != 0) {
             $title = '';
             // If a title-attribute exists
             if ($response_title->count() != 0) {
                 $title = '<title>' . $response_title->html() . '</title>';
             }
             // Set new content for the response
             $response->setContent($title . $response_container->html());
         }
         // Updating address bar with the last URL in case there were redirects
         $response->header('X-PJAX-URL', $request->getRequestUri());
     }
     return $response;
 }
Ejemplo n.º 8
0
 /**
  * @param Show $show
  * @param Episode $episode
  * @param Crawler $page
  * @return null|string
  */
 protected function extractMagnetUrl(Show $show, Episode $episode, Crawler $page)
 {
     $nodes = $page->filter(".detName");
     if ($nodes->count() == 0) {
         return null;
     }
     $tr = $page->filter('#searchResult tr')->eq(1);
     $link = new MagnetLink();
     $a = $tr->filter('td')->eq(1)->filter('a')->eq(0);
     if (!$a) {
         return null;
     }
     $link->setDetailsLink("http://{$this->domain}{$a->attr('href')}");
     $link->setLink(trim($tr->filter('a[title="Download this torrent using magnet"]')->attr('href')));
     $link->setTitle(trim($tr->filter('.detName')->eq(0)->text()));
     $desc = $tr->filter('.detDesc')->text();
     if (!preg_match('/^\\S+ (.*), .*\\s(\\S+)\\s.*,.*\\s(.*)$/', $desc, $matches)) {
         return null;
     }
     $link->setUploaded(trim($matches[1]));
     $link->setSize(trim($matches[2]));
     $link->setAuthor(trim($matches[3]));
     $link->setSeeds(trim($tr->filter('td')->eq(2)->text()));
     $link->setLeeches(trim($tr->filter('td')->eq(3)->text()));
     $link->setEpisode($episode);
     $link->setShow($show);
     return $link;
 }
 /**
  * @param $codeCountry
  *
  * @return Crawler
  */
 private function filterCountryDetails($codeCountry)
 {
     $htmlCountry = file_get_contents('https://galaxy.esn.org/section/' . $codeCountry . "/");
     $crawlerCountry = new Crawler($htmlCountry);
     $countriesElement = $crawlerCountry->filter('div.scrinfo');
     return $countriesElement;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // read url parameter
     $url = $input->getArgument('url');
     // read page parameter
     $page = $input->getArgument('page');
     if (is_numeric($page)) {
         $url = $url . "?page=" . $page;
     }
     // get url content
     $pageContent = file_get_contents($url);
     if ($pageContent !== false) {
         $ph = new PersonHandler();
         $ph->setPersonsUrl($url);
         // read persons table
         $crawler = new Crawler($pageContent);
         $rowElements = $crawler->filter('.view-persona .view-content table.views-table tbody tr');
         // extract each Person
         /* @var $rowElement DOMElement */
         foreach ($rowElements as $rowElement) {
             $p = new Person();
             $ph->readInfo($p, $rowElement);
             $output->writeln($p->toCsv());
         }
     }
 }
Ejemplo n.º 11
0
 public function query($departure, $arrival, \DateTime $date = null)
 {
     $date = $date ? $date : new \DateTime();
     $fmt = new \IntlDateFormatter('en_EN', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, date_default_timezone_get(), \IntlDateFormatter::TRADITIONAL);
     $response = $this->client->post('bin/query.exe/fn', array('headers' => array('host' => 'fahrplan.sbb.ch', 'origin' => 'http://fahrplan.sbb.ch', 'referer' => 'http://fahrplan.sbb.ch/bin/query.exe/fn'), 'form_params' => array('queryPageDisplayed' => 'yes', 'HWAI=JS!ajax' => 'yes', 'HWAI=JS!js' => 'yes', 'HWAI' => '~CONNECTION!', 'REQ0Total_KissRideMotorClass' => '404', 'REQ0Total_KissRideCarClass' => '5', 'REQ0Total_KissRide_maxDist' => '10000000', 'REQ0Total_KissRide_minDist' => '0', 'REQComparisonCarload' => '0', 'REQ0JourneyStopsS0G' => $departure['value'], 'REQ0JourneyStopsS0ID' => $departure['id'], 'REQ0JourneyStopsS0A' => '255', 'REQ0JourneyStopsZ0G' => $arrival['value'], 'REQ0JourneyStopsZ0ID' => $arrival['id'], 'REQ0JourneyStopsZ0A' => '255', 'REQ0JourneyStops1.0G' => '', 'REQ0JourneyStops1.0A' => '1', 'REQ0JourneyStopover1' => '', 'date' => sprintf('%s, %s', substr($fmt->format($date), 0, 2), $date->format('d-m-y')), 'REQ0JourneyTime' => $date->format('H:i'), 'REQ0HafasSearchForw' => '1', 'REQ0JourneyStops2.0G' => '', 'REQ0JourneyStops2.0A' => '1', 'REQ0JourneyStopover2' => '', 'REQ0JourneyStops3.0G' => '', 'REQ0JourneyStops3.0A' => '1', 'REQ0JourneyStopover3' => '', 'REQ0JourneyStops4.0G' => '', 'REQ0JourneyStops4.0A' => '1', 'REQ0JourneyStopover4' => '', 'REQ0JourneyStops5.0G' => '', 'REQ0JourneyStops5.0A' => '1', 'REQ0JourneyStopover5' => '', 'existOptimizePrice' => '0', 'existUnsharpSearch' => 'yes', 'REQ0HafasChangeTime' => '0:1', 'existHafasAttrExc' => 'yes', 'REQ0JourneyProduct_prod_0' => '1', 'existProductBits0' => 'yes', 'REQ0JourneyProduct_prod_1' => '1', 'REQ0JourneyProduct_prod_2' => '1', 'REQ0JourneyProduct_prod_3' => '1', 'REQ0JourneyProduct_prod_4' => '1', 'REQ0JourneyProduct_prod_5' => '1', 'REQ0JourneyProduct_prod_6' => '1', 'REQ0JourneyProduct_prod_7' => '1', 'REQ0JourneyProduct_prod_8' => '1', 'REQ0JourneyProduct_prod_9' => '1', 'REQ0JourneyProduct_opt_section_0_list' => '0:0000', 'disableBaim' => 'yes', 'REQ0HafasHandicapLimit' => '4:4', 'changeQueryInputData' => 'yes', 'start' => 'Chercher correspondance')));
     $crawler = new Crawler(utf8_encode((string) $response->getBody()));
     $overviews = array();
     $date = '';
     // Get overviews
     $crawler->filter('.hfs_overview .overview')->each(function (Crawler $node) use(&$overviews, &$date) {
         // Update date
         if (false !== strpos($node->getNode(0)->getAttribute('class'), 'dateHint')) {
             // Subtract 8 last chars
             $date = substr($text = trim($node->text()), ($len = strlen($text)) - 8, $len);
             return;
         }
         $overviews[] = array_filter(array($date, count($n = $node->filter('.time.departure')) ? substr(trim($n->text()), 0, 5) : null, count($n = $node->filter('.time.arrival')) ? substr(trim($n->text()), 0, 5) : null, count($n = $node->filter('.duration')) ? trim($n->text()) : null, count($n = $node->filter('.changes')) ? trim($n->text()) : null, count($n = $node->filter('.products')) ? trim($n->text()) : null, sprintf('%s%s', count($n = $node->filter('.top img')) ? trim($n->attr('alt')) : null, count($n = $node->filter('.him_icon img')) ? trim($n->attr('alt')) : null)), function ($v) {
             return $v !== null;
         });
     });
     // Combine overviews
     $_overviews = array();
     for ($i = 0; $i < count($overviews) / 2; $i++) {
         $overview = $overviews[$i * 2] + $overviews[$i * 2 + 1];
         ksort($overview);
         $_overviews[] = array_combine(array('date', 'departure', 'arrival', 'duration', 'change', 'product', 'infos'), $overview);
     }
     return $_overviews;
 }
Ejemplo n.º 12
0
 /**
  * @param $html
  * @return \Jaroska\Employees\Employee
  */
 public function parse($html)
 {
     $crawler = new Crawler($html);
     $content = $crawler->filter('.content')->first();
     $employee = new Employee();
     $employee->name = $content->filter('h1')->first()->text();
     $list = $content->filter('ul > li');
     $employee->otherInfo = $list->each(function (Crawler $item) {
         return $item->text();
     });
     $node = $content->filter('ul')->getNode(0);
     while ($node->nextSibling) {
         $node = $node->nextSibling;
         if (strpos($node->nodeValue, 'E-mail')) {
             $employee->email = $this->parseEmail($node->nodeValue);
         }
         if (strpos($node->nodeValue, 'Telefon')) {
             $employee->telephone = $this->parseTelephone($node->nodeValue);
         }
         if (strpos($node->nodeValue, 'Web')) {
             $employee->website = $node->nextSibling->attributes->getNamedItem('href')->nodeValue;
         }
     }
     $image = $content->filter('img');
     if (count($image)) {
         $employee->image = $image->first()->attr('src');
     }
     return $employee;
 }
 public function setUp()
 {
     $html = file_get_contents(__DIR__ . '/../Fixtures/category-page-product-node.html');
     $crawler = new Crawler();
     $crawler->addHtmlContent($html, 'ISO-8859-1');
     $this->SUT = new SUT($crawler);
 }
Ejemplo n.º 14
0
 public function getPdfHash($html, $cssVersion)
 {
     $crawler = new Crawler($html);
     $layoutWrapper = $crawler->filter('div#layout-main-wrapper');
     $htmlHash = $this->getHtmlHash($layoutWrapper);
     return md5($htmlHash . $cssVersion);
 }
 /**
  * @param string $query
  * @return SearchResult[]
  */
 public function search($query)
 {
     try {
         $response = $this->httpClient->get('http://kickasstorrents.to/usearch/' . urlencode($query) . '/');
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         return [];
     }
     $crawler = new Crawler((string) $response->getBody());
     $items = $crawler->filter('#mainSearchTable tr');
     $results = [];
     $i = 0;
     foreach ($items as $item) {
         // Ignores advertisement and header
         if ($i < 2) {
             $i++;
             continue;
         }
         $itemCrawler = new Crawler($item);
         $name = $itemCrawler->filter('.cellMainLink')->text();
         if (!stristr($name, $query)) {
             continue;
         }
         $data = json_decode(str_replace("'", '"', $itemCrawler->filter('div[data-sc-params]')->attr('data-sc-params')));
         $result = new SearchResult();
         $result->setName($name);
         $result->setSeeders((int) $itemCrawler->filter('td:nth-child(5)')->text());
         $result->setLeechers((int) $itemCrawler->filter('td:nth-child(6)')->text());
         $result->setMagnetUrl($data->magnet);
         $results[] = $result;
     }
     return $results;
 }
Ejemplo n.º 16
0
 /**
  * @param string $url The url to scrape.
  * @return \Slice\CliApp\ScrapeResults The results of the scrape task.
  */
 public function getProductsForUrl($url)
 {
     //Grab the remote document contents
     $rawHTML = $this->downloader->download($url);
     //Drop it into a DOM crawler
     $crawler = new Crawler();
     $crawler->addContent($rawHTML);
     try {
         //Use xPath to find all of the product li elements
         $productList = $crawler->filterXPath($this->productListXpath);
     } catch (\InvalidArgumentException $e) {
         //Convert into a Scrape Exception for easy handling by the command
         throw new ScrapeException($this->configValues['error_msg']['product_parse_error']);
     }
     //If there are none the page isn't supported
     if (sizeof($productList) == 0) {
         throw new ScrapeException($this->configValues['error_msg']['no_products']);
     }
     //Loop over each product li
     $productList->each(function ($liCrawler, $i) {
         try {
             //Find the product detail page url from the link
             $productURL = $liCrawler->filterXPath($this->pdpLinkXpath)->attr('href');
         } catch (\InvalidArgumentException $e) {
             //Convert into a Scrape Exception for easy handling by the command
             throw new ScrapeException($this->configValues['error_msg']['product_parse_error']);
         }
         $product = $this->pdpParser->parseUrl($productURL);
         //Populate the final results container
         $this->results->addProduct($product);
     });
     return $this->results;
 }
Ejemplo n.º 17
0
 /**
  * Display a page in studio and allow to add/edit gadget
  * @param $id id of the page to display
  */
 public function viewAction($id)
 {
     //Curent app id
     $appid = $this->get('keosu_core.curapp')->getCurApp();
     $em = $this->get('doctrine')->getManager();
     //Get the page we want to edit
     $page = $em->getRepository('KeosuCoreBundle:Page')->find($id);
     //Page Template content as String
     $templateHtml = file_get_contents(TemplateUtil::getPageTemplateAbsolutePath() . $page->getTemplateId());
     //Get all the elements of class "zone" in template dom
     $crawler = new Crawler($templateHtml);
     $zones = $crawler->filter('.zone')->extract(array('id'));
     //Initiate an Array to store all zone in page
     $zoneModelList = array();
     foreach ($zones as $zone) {
         //Look if there is a shared gadget in this zone
         $gadget = $em->getRepository('KeosuCoreBundle:Gadget')->findSharedByZoneAndApp($zone, $appid);
         //If there is no share gadget we try to find the specific one
         if ($gadget == null) {
             //Find the gadget associated with page and zone
             $gadget = $em->getRepository('KeosuCoreBundle:Gadget')->findOneBy(array('zone' => $zone, 'page' => $id));
         }
         $zoneModel = array();
         $zoneModel['gadget'] = $gadget;
         $zoneModel['zoneId'] = $zone;
         $zoneModelList[] = $zoneModel;
     }
     $gadgetList = array();
     $packageList = $this->get('keosu_core.package_manager')->getPackageList(PackageManager::TYPE_PACKAGE_GADGET);
     foreach ($packageList as $p) {
         $gadgetList[] = $p->getName();
     }
     return $this->render('KeosuCoreBundle:Page:studio.html.twig', array('page' => $page, 'zones' => $zoneModelList, 'templatehtml' => $templateHtml, 'gadgets' => $gadgetList));
 }
 public function format(Crawler $crawler, array $config)
 {
     $locations = $config['locations'];
     $return = $crawler->each(function (Crawler $node, $i) use($locations) {
         // Symfony dom-crawler methods ignore text nodes, so we have to
         // revert to native DOMNode methods instead.
         $children = $node->getNode(0)->childNodes;
         $values = [];
         foreach ($children as $child) {
             // Skip non element or text nodes.
             if (!in_array($child->nodeType, [1, 3])) {
                 continue;
             }
             // Loop through locations but stop after the first truthy value.
             foreach ($locations as $location) {
                 if ('_text' === $location && ($value = trim($child->nodeValue))) {
                     $values[] = $value;
                     continue 2;
                 }
                 // DOMText does not have method hasAttribute.
                 if (1 === $child->nodeType && $child->hasAttribute($location) && ($value = trim($child->getAttribute($location)))) {
                     $values[] = $value;
                     continue 2;
                 }
             }
         }
         // Remove any lingering 'empty' elements.
         $value = implode(' ', array_filter(array_map('trim', $values)));
         if ($this->looksLikeGroupTitle($node)) {
             $value = '%%TITLE%%' . $value . '%%TITLE%%';
         }
         return $value;
     });
     return [array_shift($return)];
 }
Ejemplo n.º 19
0
 /**
  * @param SymfonyCrawler $crawler
  */
 protected function getUrlsAndDownload(SymfonyCrawler $crawler)
 {
     $nodeValues = $crawler->filter('a.download-button')->each(function (SymfonyCrawler $node) {
         return $node->attr('href');
     });
     $this->download($nodeValues);
 }
Ejemplo n.º 20
0
 /**
  * @param string $rawResponse
  *
  * @return Torrent[]
  */
 protected function transformResponse($rawResponse)
 {
     $crawler = new Crawler(gzdecode($rawResponse));
     return $crawler->filter('tr[id^="torrent_"]')->each(function ($node) {
         $magnet = $node->filter('.ka-magnet')->parents()->attr('href');
         preg_match('/btih:([0-9A-Za-z]+)&/', $magnet, $matches);
         $hash = $matches[1];
         $size = $node->filter('td.nobr')->text();
         preg_match('/([0-9\\.]+) ([A-Za-z]+)/', $size, $matches);
         $size = $matches[1];
         $unit = $matches[2];
         $converter = new Nomnom($size);
         $torrent = new Torrent();
         $torrent->setName($node->filter('a.cellMainLink')->text());
         $torrent->setHash($hash);
         $torrent->setMagnet($magnet);
         if ($unit == 'KB') {
             $unit = 'kB';
         }
         $torrent->setSize($converter->from($unit)->to('B'));
         $torrent->setSeeds($node->filter('td.green')->text());
         $torrent->setPeers($node->filter('td.red')->text());
         return $torrent;
     });
 }
Ejemplo n.º 21
0
 public function show()
 {
     $options = Config::get('onepager.options');
     $progressBar = Cache::get('progressBar', function () {
         $c = curl_init('https://www.startnext.com/sanktionsfrei/widget/?w=200&amp;h=300&amp;l=de');
         curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
         $html = curl_exec($c);
         if (curl_error($c)) {
             die(curl_error($c));
         }
         $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
         curl_close($c);
         $percent = 0;
         if ($status == 200) {
             $crawler = new Crawler();
             $crawler->addHTMLContent($html, 'UTF-8');
             // get the percentage for the progressbar
             $styleString = $crawler->filter('.bar.bar-1')->attr('style');
             $stringArray = explode(':', $styleString);
             $percent = substr($stringArray[1], 0, -2);
             // get the text for the progressbar
             $textArray = $crawler->filter('.status-text span')->extract(['_text']);
         }
         return ['percent' => $percent, 'progressText' => $textArray[0]];
     }, 5);
     return view('home', ['options' => $options, 'percent' => $progressBar['percent'], 'progressText' => $progressBar['progressText']]);
 }
Ejemplo n.º 22
0
 /**
  * @Given /^I select the "([^""]*)"$/
  */
 public function iSelectThe($id)
 {
     $html = $this->getSession()->getPage()->getHtml();
     $crawler = new Crawler($html);
     $element = $crawler->filter('#' . $id)->first();
     $element->addHtmlContent('checked');
 }
 /**
  * Init object storage
  */
 public function attachAll()
 {
     $defaultRate = 1;
     // Add euro
     $euro = new $this->currencyClass();
     $euro->setCode('EUR');
     $euro->setRate(1);
     $this[$euro->getCode()] = $euro;
     // Get other currencies
     // @todo timeout + try catch
     $xml = @simplexml_load_file($this->ecbUrl);
     if ($xml instanceof \SimpleXMLElement) {
         $crawler = new Crawler($xml->asXML());
         $datas = $crawler->filter('cube > cube > cube')->extract(array('currency', 'rate'));
         foreach ($datas as $data) {
             if (in_array($data[0], $this->managedCurrencies)) {
                 $currency = new $this->currencyClass();
                 $currency->setCode($data[0]);
                 $currency->setRate($data[1]);
                 $this[$currency->getCode()] = $currency;
             }
         }
         if (isset($this[$this->defaultCurrency])) {
             $defaultRate = $this[$this->defaultCurrency]->getRate();
         }
         $this->convertAll($defaultRate);
     }
 }
Ejemplo n.º 24
0
 public function setLaundryState(&$laundryPlace)
 {
     $user = '******';
     $pass = '******';
     try {
         $client = new Client($laundryPlace['url']);
         $request = $client->get('/LaundryState', [], ['auth' => [$user, $pass, 'Digest'], 'timeout' => 1.5, 'connect_timeout' => 1.5]);
         $response = $request->send();
         $body = $response->getBody();
         libxml_use_internal_errors(true);
         $crawler = new Crawler();
         $crawler->addContent($body);
         foreach ($crawler->filter('img') as $img) {
             $resource = $img->getAttribute('src');
             $img->setAttribute('src', 'http://129.241.126.11/' . trim($resource, '/'));
         }
         $crawler->addHtmlContent('<h1>foobar</h1>');
         //'<link href="http://129.241.126.11/pic/public_n.css" type="text/css">');
         $laundryPlace['html'] = $crawler->html();
         libxml_use_internal_errors(false);
         preg_match_all('/bgColor=Green/', $body, $greenMatches);
         preg_match_all('/bgColor=Red/', $body, $redMatches);
         $laundryPlace['busy'] = count($redMatches[0]);
         $laundryPlace['available'] = count($greenMatches[0]);
     } catch (\Exception $e) {
         $laundryPlace['available'] = self::NETWORK_ERROR;
         $laundryPlace['busy'] = self::NETWORK_ERROR;
         $laundryPlace['html'] = self::NETWORK_ERROR;
     }
 }
 public function onRenderAdminProductCategoryEditBefore(FilterResponseEvent $event)
 {
     $app = $this->app;
     $request = $event->getRequest();
     $response = $event->getResponse();
     $id = $request->attributes->get('id');
     $CategoryContent = null;
     if ($id) {
         $CategoryContent = $app['category_content.repository.category_content']->find($id);
     }
     if (is_null($CategoryContent)) {
         $CategoryContent = new \Plugin\CategoryContent\Entity\CategoryContent();
     }
     // DomCrawlerにHTMLを食わせる
     $html = $response->getContent();
     $crawler = new Crawler($html);
     $form = $app['form.factory']->createBuilder('admin_category')->getForm();
     $form['content']->setData($CategoryContent->getContent());
     $form->handleRequest($request);
     $twig = $app->renderView('CategoryContent/Resource/template/Admin/category.twig', array('form' => $form->createView()));
     $oldCrawler = $crawler->filter('form')->first();
     // DomCrawlerからHTMLを吐き出す
     $html = $crawler->html();
     $oldHtml = '';
     $newHtml = '';
     if (count($oldCrawler) > 0) {
         $oldHtml = $oldCrawler->html();
         $newHtml = $oldHtml . $twig;
     }
     $html = str_replace($oldHtml, $newHtml, $html);
     $response->setContent($html);
     $event->setResponse($response);
 }
Ejemplo n.º 26
0
 public function __invoke(RequestInterface $request, array $options)
 {
     $fn = $this->nextHandler;
     if (empty($options['ftp_credentials'])) {
         return $fn($request, $options);
     } elseif (!$options['ftp_credentials'] instanceof FtpCredentials) {
         throw new \RuntimeException(sprintf('The "ftp_credentials" key must be an instance of "%s".', FtpCredentials::class));
     }
     $credentials = $options['ftp_credentials'];
     return $fn($request, $options)->then(function (ResponseInterface $response) use($credentials, $request, $options) {
         $crawler = new Crawler((string) $response->getBody(), (string) $request->getUri());
         try {
             // Try to find the form.
             $formNode = $crawler->filter('form#authorize-filetransfer-form');
             if (!$formNode->count()) {
                 return $response;
             }
             // Form found - do we have the credentials?
             if (!$credentials->present()) {
                 throw new FtpCredentialsRequiredException();
             }
             $ftpForm = $formNode->form();
             if (!empty($options['__ftp_credentials_submitted'])) {
                 // The form was already submitted and we got it again - must be with an error message.
                 $error = null;
                 $errorNode = $crawler->filter('p.error');
                 if ($errorNode->count()) {
                     $error = $errorNode->text() ?: null;
                 }
                 throw new FtpCredentialsErrorException($error);
             }
             // connection_settings[authorize_filetransfer_default]:ftp
             // connection_settings[ftp][username]:
             // connection_settings[ftp][password]:
             // connection_settings[ftp][advanced][hostname]:localhost
             // connection_settings[ftp][advanced][port]:21
             // connection_settings[ssh][username]:
             // connection_settings[ssh][password]:
             // connection_settings[ssh][advanced][hostname]:localhost
             // connection_settings[ssh][advanced][port]:22
             $submitValues = $ftpForm->getValues();
             // This is not handled by the form component, but Drupal requires this button to be pressed.
             // The "Continue" string does not have to be translated upon continuing, it's just here for
             // the convenience.
             $submitValues['process_updates'] = 'Continue';
             $submitValues['connection_settings']['authorize_filetransfer_default'] = $credentials->getMethod();
             $submitValues['connection_settings'][$credentials->getMethod()] = ['username' => $credentials->getUsername(), 'password' => $credentials->getPassword(), 'advanced' => ['hostname' => $credentials->getHost(), 'port' => $credentials->getPort()]];
         } catch (FtpCredentialsRequiredException $e) {
             throw $e;
         } catch (FtpCredentialsErrorException $e) {
             throw $e;
         } catch (\Exception $e) {
             // The form was not found - continue.
             return $response;
         }
         $newRequest = $request->withMethod($ftpForm->getMethod())->withUri(new Uri($ftpForm->getUri()))->withBody(\GuzzleHttp\Psr7\stream_for(http_build_query($submitValues, null, '&')))->withHeader('content-type', 'application/x-www-form-urlencoded');
         $options['__ftp_credentials_submitted'] = true;
         return $this($newRequest, $options);
     });
 }
Ejemplo n.º 27
0
 protected function pruneUserComments(Issue $issue, DoBrowser $browser, $comment_words, InputInterface $input, OutputInterface $output)
 {
     $deleted_comments = 0;
     /** @var \DOMElement $comment */
     foreach ($issue->getCrawler()->filter('section.comments div.comment') as $comment) {
         $words = 0;
         $crawler = new Crawler($comment);
         if ($crawler->filter('.nodechanges-file-changes')->count() > 0) {
             // Has a file attached ignore.
             continue;
         }
         $comment_body = $crawler->filter('.field-name-comment-body div.field-item');
         if ($comment_body->count()) {
             $text = $comment_body->text();
             $words = str_word_count(trim($text));
         }
         // Zero word comments are often issue summary updates extra - ignore them
         // for now.
         if ($words <= $comment_words) {
             $changes = $crawler->filter('.field-name-field-issue-changes div.field-item');
             if ($changes->count()) {
                 $output->writeln("Comment issue changes: " . trim($changes->text()));
             }
             $output->writeln("Comment text: " . trim($text));
             if ($this->askConfirmation($input, $output, 'Delete this comment (yes/NO)? ')) {
                 $delete_link = $crawler->filter('li.comment-delete a, div.system-message.queued-retesting li.comment-delete a')->extract(array('href'));
                 $delete_link = $delete_link[0];
                 $this->deleteComment($delete_link, $browser, $output);
                 $deleted_comments++;
             }
             $output->writeln('');
         }
     }
     $output->writeln("Deleted {$deleted_comments} user comments.");
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $app = $this->app;
     $this->app->after(function ($request, $response) use($app) {
         // Only handle non-redirections
         if (!$response->isRedirection()) {
             // Must be a pjax-request
             if ($request->server->get('HTTP_X_PJAX')) {
                 $crawler = new Crawler($response->getContent());
                 // Filter to title (in order to update the browser title bar)
                 $response_title = $crawler->filter('head > title');
                 // Filter to given container
                 $response_container = $crawler->filter($request->server->get('HTTP_X_PJAX_CONTAINER'));
                 // Container must exist
                 if ($response_container->count() != 0) {
                     $title = '';
                     // If a title-attribute exists
                     if ($response_title->count() != 0) {
                         $title = '<title>' . $response_title->html() . '</title>';
                     }
                     // Set new content for the response
                     $response->setContent($title . $response_container->html());
                 }
                 // Updating address bar with the last URL in case there were redirects
                 $response->header('X-PJAX-URL', $request->getRequestUri());
             }
         }
     });
 }
 public function onRenderAdminProductEditBefore(FilterResponseEvent $event)
 {
     $app = $this->app;
     $request = $event->getRequest();
     $response = $event->getResponse();
     // メーカーマスタから有効なメーカー情報を取得
     $repos = $app['eccube.plugin.mail_magazine.repository.mail_magazine'];
     $MailMagazines = $repos->findAll();
     if (is_null($MailMagazines)) {
         $MailMagazines = new \Plugin\MailMagazine\Entity\MailMagazine();
     }
     // 商品登録・編集画面のHTMLを取得し、DOM化
     $crawler = new Crawler($response->getContent());
     $form = $app['form.factory']->createBuilder('admin_product_mail_magazine')->getForm();
     $form->get('mail_magazine')->setData($MailMagazines);
     $form->handleRequest($request);
     $parts = $app->renderView('MailMagazine/View/admin/product_mail_magazine.twig', array('form' => $form->createView()));
     // form1の最終項目に追加(レイアウトに依存(時間無いのでベタ))
     $html = $crawler->html();
     $form = $crawler->filter('#form1 .accordion')->last()->html();
     $new_form = $form . $parts;
     $html = str_replace($form, $new_form, $html);
     $response->setContent($html);
     $event->setResponse($response);
 }
Ejemplo n.º 30
-1
 protected function process($content)
 {
     $parser = new Parser('yaml', 'markdown');
     $frontmatter = $parser->parse($content);
     $crawler = new Crawler();
     $crawler->addHtmlContent($frontmatter->getBody());
     $title = '';
     $crawler->filterXPath('//h1')->each(function (Crawler $crawler) use(&$title) {
         foreach ($crawler as $node) {
             if (!$title) {
                 $title = $node->nodeValue;
             }
             $node->parentNode->removeChild($node);
         }
     });
     $images = $crawler->filterXPath('//img');
     foreach ($images as $image) {
         $src = $image->getAttribute('src');
         $image->setAttribute('src', str_replace('../..', '', $src));
     }
     $body = $crawler->html();
     $intro = explode('<hr>', $body)[0];
     $body = str_replace('<hr>', '', $body);
     return ['title' => $title ?: '', 'keywords' => isset($frontmatter->head['keywords']) ? $frontmatter->head['keywords'] : '', 'description' => isset($frontmatter->head['description']) ? $frontmatter->head['description'] : mb_substr(strip_tags(trim($intro)), 0, 150), 'intro' => trim($intro), 'cover' => isset($frontmatter->head['cover']) ? $frontmatter->head['cover'] : '', 'content' => trim($body), 'tags' => isset($frontmatter->head['tags']) ? $frontmatter->head['tags'] : ''];
 }