本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::text方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::text方法的具体用法?PHP Crawler::text怎么用?PHP Crawler::text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DomCrawler\Crawler
的用法示例。
在下文中一共展示了Crawler::text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
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;
}
示例2: parseDay
public static function parseDay($rows)
{
$result = array();
foreach ($rows as $item) {
$crawler = new Crawler($item);
$anime = new Anime();
$url = $crawler->filter('a[class="link-title"]')->attr('href');
$id = preg_match('/\\/(anime|manga)\\/(\\d+)\\/.*?/', $url, $urlParts);
if ($id !== false || $id !== 0) {
$anime->setId((int) $urlParts[2]);
}
$anime->setTitle(trim($crawler->filter('a[class="link-title"]')->text()));
$producer = $crawler->filter('span[class="producer"] a');
if ($producer->count() > 0) {
$anime->setProducers(explode(', ', $crawler->filter('span[class="producer"] a')->text()));
}
$anime->setEpisodes((int) str_replace(' eps', '', $crawler->filter('div[class="eps"] span')->text()));
$genres = $crawler->filter('div[class="genres-inner js-genre-inner"] a');
$genreArray = array();
foreach ($genres as $genre) {
$genreCrawler = new Crawler($genre);
$genreArray[] = $genreCrawler->text();
}
$anime->setGenres($genreArray);
$anime->setImageUrl($crawler->filter('div[class="image lazyload"]')->attr('data-bg'));
$anime->setSynopsis(trim($crawler->filter('div[class="synopsis js-synopsis"]')->text()));
$detail = explode('-', $crawler->filter('div[class="info"]')->text());
$anime->setType(trim($detail[0]));
$anime->setMembersCount((int) str_replace(',', '', trim($crawler->filter('span[class="member fl-r"]')->text())));
$anime->setMembersScore((double) trim($crawler->filter('span[class="score"]')->text()));
$result[] = $anime;
}
return $result;
}
示例3: parseTeachersName
/**
* @param Crawler $crawler
* @return string
*/
private function parseTeachersName(Crawler $crawler)
{
$str = $crawler->text();
$str = str_replace('Vyučující: ', '', $str);
$str = str_replace('(email)', '', $str);
return trim($str);
}
示例4: parseTextFromNode
/**
* Parse text from crawler node.
*
* @param \Symfony\Component\DomCrawler\Crawler $node
* @param mixed $default
*
* @return mixed
*/
protected function parseTextFromNode($node, $default = null)
{
$text = trim($node->text());
if (strlen($text) === 0) {
return $default;
}
return $text;
}
示例5: normalisePrice
/**
* Нормализует значение цены на блюдо
*
* @param Crawler|null $element
* @return float
*/
public function normalisePrice(Crawler $element = null)
{
if ($element === null) {
return 0.0;
}
$price = (string) $element->text();
return (double) str_replace(',', '.', $price);
}
示例6: getPageData
private function getPageData($html)
{
$crawler = new Crawler($html);
$body = $crawler->filter('body');
$header = $body->filter('.page-header');
$breadcrumbs = $header->filter('.breadcrumb li span a')->each(function (Crawler $crawler) {
return trim($crawler->text());
});
$descriptions = $body->filter('.container > .row .profile')->each(function (Crawler $crawler) {
return trim($crawler->text());
});
$default = array_fill(0, 3, '');
$descriptions = $descriptions + $default;
$breadcrumbs = $breadcrumbs + $default;
$data = ['city' => $breadcrumbs[1], 'category' => $breadcrumbs[2], 'title' => trim($header->filter('h1')->text()), 'salary' => substr(trim($header->filter('.profile-details-salary')->text()), 1), 'experience_year' => (int) $body->filter('.before-hint')->text(), 'experience_description' => $descriptions[0], 'achievement' => $descriptions[1], 'expect' => $descriptions[2], 'skills' => json_encode($this->getSkills($body))];
return $data;
}
示例7: extract
protected function extract(Crawler $crawler)
{
// mother fuckin callback nigga
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();
});
});
}
示例8: parseFromDomCrawler
/**
* @param Crawler $crawler
* @return Person
*/
public static function parseFromDomCrawler(Crawler $crawler)
{
$content = $crawler->text();
$content = StringHelper::removeEmptyLines($content);
$contentItems = explode("\n", $content);
$contentItems = array_map('trim', $contentItems);
$name = trim(explode(',', $contentItems[1])[0]);
$birthday = DateTimeParser::parseFromCzechDateString($contentItems[2]);
return new Person($name, $birthday, $contentItems[3]);
}
示例9: getPageTags
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');
});
}
示例10: looksLikeGroupTitle
protected function looksLikeGroupTitle(Crawler $node)
{
$tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'strong', 'dt'];
if (in_array($node->nodeName(), $tags)) {
return true;
}
if (preg_match('/[#\\*\\-_=\\+]{2,}/', $node->text())) {
return true;
}
if (':' === substr($node->text(), -1)) {
return true;
}
if (false !== strpos($node->attr('class'), 'header')) {
return true;
}
if (false !== strpos($node->attr('class'), 'title')) {
return true;
}
return false;
}
示例11: populateLeagues
public function populateLeagues($crawler)
{
$types = [];
foreach ($crawler->filterXPath('//*[@class="ismSecondary"]/*[@class="ismTableHeading"]') as $h) {
$c = new Crawler($h);
if (preg_match('~ leagues$~', $c->text())) {
$types[] = strtolower(preg_replace('~ leagues$~', '', $c->text()));
}
}
foreach ($crawler->filterXPath('//*[@class="ismTable ismLeagueTable"]') as $i => $t) {
$table = new Crawler($t);
$leagues = $table->filterXpath('//tbody/tr');
foreach ($leagues as $l) {
$c = new Crawler($l);
$league = new UserLeague();
$league->type = $types[$i];
$league->populate($c);
$this->leagues[] = $league;
}
}
}
示例12: testMessageRender
public function testMessageRender()
{
$message = new FlashMessage();
$message->title = 'Error!';
$message->type = FlashMessage::TYPE_ERROR;
$message->message = 'This is a test error';
Yii::$app->session->setFlash('test', $message);
$html = FlashMessages::widget(['id' => 'flash-test']);
$dom = new Crawler($html);
$this->assertContains('This is a test error', $dom->text());
$this->assertContains('Error!', $dom->filter('h4')->text());
}
示例13: addToCart
private function addToCart($mealName, $quantity, Crawler $crawler, Client $client)
{
$titles = $crawler->filter('h4')->reduce(function ($crawler) use($mealName) {
return false !== strpos($crawler->text(), $mealName);
});
if (count($titles) !== 1) {
throw new \RuntimeException(sprintf('Expected 1 title containing "%s", found %s.', $mealName, count($titles)));
}
$link = $titles->eq(0)->parents()->first()->filter('input[data-meal]');
$mealId = $link->attr('data-meal');
$client->request('POST', '/cart', array('meal' => $mealId, 'mode' => 'add', 'quantity' => $quantity));
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
示例14: each
private function each(Crawler $node, $rule)
{
$elements = [];
// '@idioms' => [':each' => '#relatedentries > dl > dd > ul > li > a > .arl8']
if (is_string($rule)) {
$node->filter($rule)->each(function (Crawler $node) use($elements) {
$value = $node->text();
if (null !== $value) {
$elements[] = $value;
}
});
} else {
foreach ($rule as $filter => $pattern) {
$node->filter($filter)->each(function (Crawler $node, $i) use(&$elements, $pattern) {
$elements[$i] = [];
$this->parse($node, $pattern, $elements[$i]);
});
}
}
return $elements;
}
示例15: lastAction
/**
* Aucune annotation Route n'a été définie pour cette méthode de controller,
* la page ne sera pas directement accessible.
*
* La méthode peut être appelée depuis un fichier de template
* {{ render(controller('MmiBlogBundle:Feed:last', {limit: 5})) }}
*/
public function lastAction($limit)
{
//import d'un flux RSS
try {
$reader = Reader::import('http://etin.yourphototravel.com/fr/etins.rss');
} catch (\Exception $e) {
$reader = array();
}
//lecture du flux RSS et préparation des paramètres à envoyer à la vue
$items = array();
$count = 0;
foreach ($reader as $item) {
$crawler = new Crawler($item->getDescription());
$items[] = array('title' => $item->getTitle(), 'link' => $item->getLink(), 'image' => $crawler->filter('img')->first()->attr('src'), 'description' => utf8_decode($crawler->text()));
$count++;
if ($count == $limit) {
break;
}
}
//création de la réponse
return $this->get('templating')->renderResponse('MmiBlogBundle:Feed:list.html.twig', array('items' => $items));
}