filter() публичный Метод

This method only works if you have installed the CssSelector Symfony Component.
public filter ( string $selector ) : Crawler
$selector string A CSS selector
Результат Crawler A new instance of Crawler with the filtered list of nodes
Пример #1
2
 public function run()
 {
     $c = new Color();
     $crawler = new Crawler();
     $response = $this->client->request('GET', $this->search . '&start=' . $this->getLimit());
     $crawler->addContent((string) $response->getBody());
     $data = file_get_contents(ROOT . '/lib/results.csv');
     foreach ($crawler->filter('cite') as $url) {
         $row = ['name' => '', 'd7' => '', 'd8' => '', 'url' => ''];
         echo "Found: {$url->nodeValue}" . PHP_EOL;
         // Attempt to make a request to D.O to get details about the module.
         $res = $this->client->request('GET', $url->nodeValue);
         if ($res->getStatusCode() > 400) {
             echo $c("Unable to fetch data")->red() . PHP_EOL;
             continue;
         }
         $body = (string) $res->getBody();
         if (empty($body)) {
             echo $c('Unable to fetch body')->red() . PHP_EOL;
             continue;
         }
         $crawl = new Crawler();
         $crawl->addContent($res->getBody());
         // Add the known elements.
         $row['name'] = trim($crawl->filter('#page-subtitle')->text());
         $row['url'] = trim($url->nodeValue);
         // The help block often has information about the status to D8.
         if (count($crawl->filter('.help'))) {
             $help = $crawl->filter('.help')->text();
             if (strpos($help, 'ported to Drupal 8') > -1) {
                 $row['d8'] = 'In progress';
             }
         }
         foreach ($crawl->filter('[data-th="Version"]') as $version) {
             $version = $version->nodeValue;
             if (strpos($version, '7.x') > -1) {
                 $row['d7'] = trim($version);
                 continue;
             }
             if (strpos($version, '8.x') > -1) {
                 $row['d8'] = trim($verison);
                 continue;
             }
         }
         // This module hasn't been ported to D7 - so continue.
         if (empty($row['d7']) && empty($row['d8'])) {
             echo $c('<bg_yellow>This is a Drupal 6 module</bg_yellow>')->colorize() . PHP_EOL;
             continue;
         }
         $data .= implode(',', array_values($row)) . "\n";
         echo $c('Successfully added metadata')->green() . PHP_EOL;
     }
     $h = fopen(ROOT . '/lib/results.csv', 'w');
     fwrite($h, $data);
     // Increment the limit.
     $limit = $this->getLimit() + 10;
     echo $c('Updating the limit from <yellow>' . $this->getLimit() . '</yellow> to <yellow>' . $limit . '</yellow>')->colorize() . PHP_EOL;
     $this->setLimit($limit);
 }
Пример #2
1
 /**
  * Add product data
  *
  * @param Crawler $node
  */
 private function addProduct(Crawler $node)
 {
     $product = new \stdClass();
     /** @var Crawler $title */
     $title = $node->filter('h3 a');
     $product->title = trim($title->text());
     $product->unit_price = $this->getPrice($node->filter('.pricePerUnit'));
     $productCrawler = $this->client->request('GET', $title->attr('href'));
     $product->size = $this->bytesToKb(strlen($this->client->getResponse()->getContent()));
     $product->description = '';
     $description = $productCrawler->filterXPath('//h3[.="Description"]');
     if ($description->count() > 0) {
         foreach ($description->siblings() as $sibling) {
             // product pages have different structures!
             if ($sibling->tagName == 'h3') {
                 break;
             }
             if ($product->description != "") {
                 $product->description .= "\n";
             }
             // @TODO address formatting issues - breaks to new lines
             $product->description .= trim(preg_replace("/[^\\S\r\n]+/", " ", $sibling->nodeValue));
             // remove excess whitespace but not new lines
         }
     }
     $this->total += $product->unit_price;
     // increment total
     $this->results[] = $product;
 }
Пример #3
0
 public static function parse($contents, $id, $type)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $rows = $crawler->filter('div[class="spaceit_pad"]');
     $title = preg_replace('/ (\\w+?) Details/', '$2', $crawler->filter('div[class="normal_header"]')->text());
     $result = array();
     if ($type === 'anime') {
         foreach ($rows as $historyItem) {
             $crawler = new Crawler($historyItem);
             $date = explode(' ', $crawler->text());
             $historyinfo['item'] = new Anime();
             $historyinfo['item']->setId((int) $id);
             $historyinfo['item']->setTitle($title);
             $historyinfo['item']->setWatchedEpisodes((int) $date[1]);
             $historyinfo['type'] = $type;
             $historyinfo['time_updated'] = Date::formatTime($date[4] . ' ' . $date[6]);
             $result[] = $historyinfo;
         }
     } else {
         foreach ($rows as $historyItem) {
             $crawler = new Crawler($historyItem);
             $date = explode(' ', $crawler->text());
             $historyinfo['item'] = new Manga();
             $historyinfo['item']->setId((int) $id);
             $historyinfo['item']->setTitle($title);
             $historyinfo['item']->setChaptersRead((int) $date[1]);
             $historyinfo['type'] = $type;
             $historyinfo['time_updated'] = Date::formatTime($date[4] . ' ' . $date[6]);
             $result[] = $historyinfo;
         }
     }
     return $result;
 }
Пример #4
0
 /**
  * @inheritdoc
  */
 protected function parse(Requests_Response $requests)
 {
     $crawler = new Crawler();
     $crawler->addContent($requests->body);
     $r = $crawler->filter("#page > main > section > div > div.result-item-list article a > .box-row");
     $results = array();
     /** @var DOMElement $el */
     foreach ($r as $el) {
         $c = new Crawler();
         $c->add($el);
         $tags = [];
         /** @var DOMElement $z */
         foreach ($c->filter(".box-row ul.box-row-item-attribute-list li") as $z) {
             if ($z->childNodes !== null && $z->childNodes->length >= 4) {
                 $tags[] = $z->childNodes->item(1)->nodeValue . ": " . $z->childNodes->item(3)->nodeValue;
             }
         }
         $addressB = $c->filter(".item-title--street");
         $address = $addressB->text() . " " . $addressB->siblings()->text();
         $tags[] = "Adresse: " . $address;
         $result = new Result();
         $result->setTags($tags);
         $result->setTitle(trim($c->filter("h2")->text()));
         if ($c->filter("item-description p")->valid()) {
             $result->setDescription($c->filter("item-description p")->text());
         }
         $link = $el->parentNode->attributes->getNamedItem("href")->nodeValue;
         $result->setId($this->getName() . "_" . explode("/", $link)[2]);
         $result->setUrl("http://m.homegate.ch/" . $link);
         $results[] = $result;
     }
     return $results;
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 protected function parse(Requests_Response $requests)
 {
     $crawler = new Crawler();
     $crawler->addContent($requests->body);
     $r = $crawler->filterXPath('//*[@id="content"]/div/div[2]/div[1]/div[1]/ul/li');
     $results = array();
     /** @var DOMElement $el */
     foreach ($r as $el) {
         $c = new Crawler();
         $c->add($el);
         $tags = [];
         /** @var DOMElement $z */
         foreach ($c->filter(".horizontal-separated-list li") as $z) {
             $tags[] = $z->textContent;
         }
         $result = new Result();
         $result->setTitle(trim($c->filter(".details a")->text()));
         $result->setTags($tags);
         $relUrl = $c->filter(".details a")->attr("href");
         $id = explode("--", explode("/", parse_url($relUrl)["path"])[2])[1];
         $result->setId($this->getName() . "_" . intval($id));
         $result->setUrl("http://www.anibis.ch/" . $relUrl);
         $result->setPrice($c->filter(".price")->text());
         $result->setDescription($c->filter(".details .description")->text());
         $results[] = $result;
     }
     return $results;
 }
Пример #6
0
 /**
  * @param Crawler $crawler
  *
  * Meta
  * - price
  * - price_per_month
  * - flexibel [bool]
  * - duration [integer]
  * - education_level [string]
  * - examination_costs [float]
  * - 21_plus_test [bool]
  * - recognized_diploma
  * - specialized_literature_amount
  * - practice_sessions_count
  */
 public function hbo(Crawler $crawler, Request $request)
 {
     $data = new ArrayObject();
     $this->fetch($request, 'title', function () use($crawler, $data) {
         $title = trim($crawler->filter('h1')->text());
         $data['title'] = $title;
         $data['uid'] = 'nti-' . Str::slug($title);
         $data['slug'] = Str::slug($title);
     });
     $this->fetch($request, 'teaser', function () use($crawler, $data) {
         $data['teaser'] = trim($crawler->filter('.ParagraafOrder_1 p')->first()->text());
     });
     $this->fetch($request, 'price', function () use($crawler, $data, $request) {
         try {
             $price = $crawler->filter('.old-lesgeld-table tr')->eq(1)->filter('td')->eq(1)->text();
             dd($price);
         } catch (\Exception $e) {
             $this->error('aaarg');
             $price = $crawler->filter('.old-lesgeld-table tr')->count();
             $this->info($request->getUri()->getPath());
             dd($price);
             dd($e->getMessage());
         }
         $data['meta'][] = ['name' => 'price', 'value' => 0];
     });
     $this->fetch($request, 'flexible', function () use($crawler, $data) {
         $data['meta'][] = ['name' => 'flexible_course', 'value' => strstr($data['title'], 'Klassikaal') ? 0 : 1];
     });
     // Save to the storage
     $this->store($request, $data);
 }
 /**
  * @param string $query
  * @return SearchResult[]
  */
 public function search($query)
 {
     try {
         $response = $this->httpClient->get('https://thepiratebay.se/search/' . urlencode($query) . '/0/7/0');
     } catch (ClientException $e) {
         return [];
     }
     $crawler = new Crawler((string) $response->getBody());
     $items = $crawler->filter('#searchResult tr');
     $results = [];
     $first = true;
     foreach ($items as $item) {
         // Ignore the first row, the header
         if ($first) {
             $first = false;
             continue;
         }
         $result = new SearchResult();
         $itemCrawler = new Crawler($item);
         $result->setName(trim($itemCrawler->filter('.detName')->text()));
         $result->setSeeders((int) $itemCrawler->filter('td')->eq(2)->text());
         $result->setLeechers((int) $itemCrawler->filter('td')->eq(3)->text());
         $result->setMagnetUrl($itemCrawler->filterXpath('//tr/td/a')->attr('href'));
         $results[] = $result;
     }
     return $results;
 }
Пример #8
0
 public static function parse($contents)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $rows = $crawler->filter('table[class="mt8 episode_list js-watch-episode-list ascend"] tr[class="episode-list-data"]');
     $result = array();
     foreach ($rows as $episodeItem) {
         $crawler = new Crawler($episodeItem);
         $episode = new Episode();
         $episode->setNumber($crawler->filter('td[class="episode-number nowrap"]')->text());
         $episode->setTitle($crawler->filter('td[class="episode-title"] a')->text());
         // MAL does not always provide the air date!
         $date = $crawler->filter('td[class="episode-aired"]')->text();
         if ($date !== 'N/A') {
             $dateTime = new DateTime();
             $episode->setAirDate($dateTime->createFromFormat('M j, Y', $date));
         }
         $extracted = $crawler->filter('td[class="episode-title"] span[class="di-ib"]');
         if ($extracted->text() !== '' && $extracted->count() > 0) {
             # English:
             $extracted = explode('(', $extracted->text());
             if (count($extracted) > 0) {
                 $other_titles['english'] = array(trim($extracted[0], chr(0xc2) . chr(0xa0)));
             }
             # Japanese:
             if (count($extracted) > 1) {
                 $other_titles['japanese'] = array(trim(str_replace(')', '', $extracted[1])));
             }
             $episode->setOtherTitles($other_titles);
         }
         $result[] = $episode;
     }
     return $result;
 }
Пример #9
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.");
 }
Пример #10
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;
 }
Пример #11
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);
     });
 }
Пример #12
0
 /**
  * @param string $query
  * @return SearchResult[]
  */
 public function search($query)
 {
     try {
         $response = $this->httpClient->get('https://eztv.ag/search/' . $this->transformSearchString($query));
     } catch (ClientException $e) {
         return [];
     }
     $crawler = new Crawler((string) $response->getBody());
     $items = $crawler->filter('tr.forum_header_border');
     $results = [];
     foreach ($items as $item) {
         $result = new SearchResult();
         $itemCrawler = new Crawler($item);
         $result->setName(trim($itemCrawler->filter('td')->eq(1)->text()));
         $result->setSeeders($this->options['seeders']);
         $result->setLeechers($this->options['leechers']);
         $node = $itemCrawler->filter('a.download_1');
         if ($node->count() > 0) {
             $result->setTorrentUrl($node->eq(0)->attr('href'));
         }
         $node = $itemCrawler->filter('a.magnet');
         if ($node->count() > 0) {
             $result->setMagnetUrl($node->eq(0)->attr('href'));
         }
         $results[] = $result;
     }
     return $results;
 }
Пример #13
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;
 }
Пример #14
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;
 }
 /**
  * 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());
             }
         }
     });
 }
 /**
  * @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;
 }
Пример #17
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']]);
 }
Пример #18
0
 /**
  * @param Crawler $crawler
  * @return ExtractedOwner
  */
 public function extractOwner(Crawler $crawler)
 {
     $owner = new ExtractedOwner();
     $owner->setName(trim(implode("", $crawler->filter(".yt-user-info")->extract(array('_text')))));
     $owner->setAvatarByUrl(trim(implode("", $crawler->filter(".yt-thumb-clip img")->extract(array('data-thumb')))));
     return $owner;
 }
 private function getSkills(Crawler $crawler)
 {
     return $crawler->filter('table.skills-table tr')->each(function (Crawler $crawler) {
         $name = trim($crawler->filter('td')->first()->text());
         $score = (int) $crawler->filter('div.skill')->attr('data-score');
         return compact('name', 'score');
     });
 }
Пример #20
0
 /**
  * Walk for each field in template.
  *
  * @param callback $callback
  * @return \Bpi\Sdk\Template
  */
 public function eachField($callback)
 {
     foreach ($this->crawler->filter('field') as $node) {
         $this->fields[] = $field = new Template\Field($node);
         $callback($field);
     }
     return $this;
 }
Пример #21
0
 /**
  * Get the current GoCard balance.
  *
  * @return string balance in xx.xx format
  */
 public function getBalance()
 {
     if (!$this->loginCrawler) {
         $this->login();
     }
     $balance = $this->loginCrawler->filter('#balance-table td:nth-of-type(2)')->text();
     return str_replace('$', '', $balance);
 }
 public function assertSonataAdminFlashSuccessMessageContains($text)
 {
     $crawler = new Crawler(static::$client->getResponse()->getContent());
     $content = '';
     if ($crawler->filter('.alert.alert-success.alert-dismissable')->count() == 1) {
         $content = trim($crawler->filter('.alert.alert-success.alert-dismissable')->text());
     }
     $this->assertContains($text, $content);
 }
Пример #23
0
 protected function extract(Crawler $crawler)
 {
     // mother f****n callback n***a
     return $crawler->filter('table.ob_gBody tr')->each(function (Crawler $crawler, $i) {
         return $crawler->filter('.ob_gCc2')->each(function (Crawler $crawler, $i) {
             return $crawler->text();
         });
     });
 }
Пример #24
0
 public function testTextareaFieldGeneration()
 {
     $model = new stdClass();
     $response = $this->formBuilder->textarea('description', $model);
     $crawler = new Crawler($response);
     $this->assertCount(2, $crawler->filter('textarea'));
     $this->assertEquals('translated[description][en_GB]', $crawler->filter('textarea')->eq(0)->attr('name'));
     $this->assertEquals('translated[description][ja_JP]', $crawler->filter('textarea')->eq(1)->attr('name'));
 }
Пример #25
0
 public function testWelcomeController()
 {
     $this->CI->index();
     $out = output();
     $crawler = new Crawler($out);
     // Check if the content is OK
     $this->assertCount(0, $crawler->filter('html:contains("PHP Error")'));
     // Check if we got the expected view
     $this->assertCount(1, $crawler->filter('title:contains("Welcome to CodeIgniter")'));
 }
Пример #26
0
 public function testPhpRenderDebug()
 {
     $kernel = new TestKernel('test', true);
     $kernel->boot();
     $container = $kernel->getContainer();
     $content = $container->get('templating')->render('::layout.html.php');
     $crawler = new Crawler($content);
     $this->assertEquals(3, count($crawler->filter('link[href$=".css"]')));
     $this->assertEquals(2, count($crawler->filter('script[src$=".js"]')));
 }
Пример #27
0
 /**
  * Method to parse the dom from a Url to create a Product.
  *
  * @param Url $url
  * @return Product
  */
 public function getProductFromUrl(Url $url)
 {
     // dom parse the information we need from the page
     $crawler = new Crawler($url->getResponseContents());
     // @todo review description data - it is a mess, crappy content?
     // are we after the meta description or value in the information tab?
     // going for information tab
     // and create the new product
     return new Product($crawler->filter("div.productSummary h1")->text(), $crawler->filter("#information div.productText")->first()->text(), $crawler->filter("p.pricePerUnit")->text(), $url);
 }
 public function testRegisterSuccess()
 {
     $this->form[self::USERNAME_FIELD] = self::USERNAME;
     $this->form[self::EMAIL_FIELD] = self::EMAIL;
     $this->form[self::PASSWORD_FIELD] = self::PASSWORD;
     $this->form[self::REPEAT_PASSWORD_FIELD] = self::PASSWORD;
     $this->crawler = $this->client->submit($this->form);
     $this->assertEmpty($this->crawler->filter(self::ERROR_SELECTOR));
     $this->assertNotEquals(self::REGISTRATION_URL, $this->client->getRequest()->getRequestUri());
 }
 private function getPageTags(Crawler $crawler)
 {
     return $crawler->filter('.item-info table tr')->each(function (Crawler $crawler) {
         $name = trim($crawler->filter('td')->first()->text());
         $list = $crawler->filter('.tag span')->each(function (Crawler $crawler) {
             return $crawler->text();
         });
         return compact('name', 'list');
     });
 }
 /**
  * Check if a page is a real error page
  *
  * @param Client  $client
  * @param Crawler $crawler
  * @param string  $code
  * @param string  $message
  */
 private function assertErrorPage(Client $client, Crawler $crawler, $code, $message = 'Something went wrong.')
 {
     // check if the code is set correctly
     $this->assertEquals($code, $client->getResponse()->getStatusCode());
     // check if the title is ok
     $this->assertEquals(sprintf('%1$s: %2$s', $code, $message), $crawler->filter('title')->html());
     // check if no-index is set
     $this->assertEquals('noindex, nofollow', $crawler->filter('meta[name=robots]')->attr('content'));
     // check if the message is ok
     $this->assertEquals(sprintf('%1$s: %2$s', $code, $message), $crawler->filter('#content h1')->html());
 }