當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Crawler::addHTMLContent方法代碼示例

本文整理匯總了PHP中Symfony\Component\DomCrawler\Crawler::addHTMLContent方法的典型用法代碼示例。如果您正苦於以下問題:PHP Crawler::addHTMLContent方法的具體用法?PHP Crawler::addHTMLContent怎麽用?PHP Crawler::addHTMLContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\DomCrawler\Crawler的用法示例。


在下文中一共展示了Crawler::addHTMLContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parse

 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;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:34,代碼來源:EpsParser.php

示例2: 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;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:34,代碼來源:HistoryParser.php

示例3: show

 public function show()
 {
     $options = Config::get('onepager.options');
     $progressBar = Cache::get('progressBar', function () {
         $c = curl_init('https://www.startnext.com/sanktionsfrei/widget/?w=200&h=300&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']]);
 }
開發者ID:johannesponader,項目名稱:Onepager,代碼行數:27,代碼來源:WelcomeController.php

示例4: parse

 public static function parse($contents, $type)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $result = array();
     $items = $crawler->filter('div [class="borderDark pt4 pb8 pl4 pr4 mb8"]');
     foreach ($items as $item) {
         $result[] = self::parseReviews($item, $type);
     }
     return $result;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:11,代碼來源:ReviewParser.php

示例5: parse

 public static function parse($contents, $type)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     //Filter into a set of tds from the source HTML table
     $mediaitems = $crawler->filter('tr[class="ranking-list"]');
     foreach ($mediaitems as $item) {
         $resultset[] = self::parseRecord($item, $type);
     }
     return $resultset;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:11,代碼來源:Top.php

示例6: getCsrfToken

 /**
  * Get the CSRF Token.
  *
  * @return string A string representing the CSRF token required for login
  */
 private function getCsrfToken()
 {
     $token = null;
     //Get the csrf_token for login
     $loginPageContent = $this->fetch('/login.php');
     $crawler = new Crawler();
     $crawler->addHTMLContent($loginPageContent, 'UTF-8');
     $metaTags = $crawler->filter('meta[name="csrf_token"]');
     foreach ($metaTags as $tag) {
         $name = $tag->attributes->getNamedItem('name');
         if ($name !== null && $name->value == 'csrf_token') {
             $token = $tag->attributes->getNamedItem('content')->value;
         }
     }
     return $token;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:21,代碼來源:Communicator.php

示例7: parse

 public static function parse($contents, $type)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $result = array();
     $items = $crawler->filter('entry');
     if ($type === 'anime') {
         foreach ($items as $item) {
             $result[] = self::parseAnime($item);
         }
     } else {
         foreach ($items as $item) {
             $result[] = self::parseManga($item);
         }
     }
     return $result;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:17,代碼來源:SearchParser.php

示例8: parse

 public static function parse($contents)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $rows = $crawler->filter('div[class="borderClass"]');
     $result = array();
     foreach ($rows as $historyItem) {
         $crawler = new Crawler($historyItem);
         $anime = new Anime();
         $anime->setId(str_replace('#raArea1', '', $crawler->filter('a')->attr('id')));
         $anime->setImageUrl(preg_replace('/r(.+?)\\/(.+?)\\?(.+?)$/', '$2', $crawler->filter('img')->attr('data-src')));
         $anime->setTitle($crawler->filter('strong')->text());
         $resultItem['item'] = $anime;
         $resultItem['recommendations'] = self::parseInformation($crawler);
         $result[] = $resultItem;
     }
     return $result;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:18,代碼來源:RecsParser.php

示例9: parse

 public static function parse($contents)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $classDay = 'seasonal-anime-list js-seasonal-anime-list js-seasonal-anime-list-key-';
     $recordContainer = 'div[class="seasonal-anime js-seasonal-anime"]';
     $result = array();
     $result['monday'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'monday clearfix"] ' . $recordContainer));
     $result['tuesday'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'tuesday clearfix"] ' . $recordContainer));
     $result['wednesday'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'wednesday clearfix"] ' . $recordContainer));
     $result['thursday'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'thursday clearfix"] ' . $recordContainer));
     $result['friday'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'friday clearfix"] ' . $recordContainer));
     $result['saturday'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'saturday clearfix"] ' . $recordContainer));
     $result['sunday'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'sunday clearfix"] ' . $recordContainer));
     $result['other'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'other clearfix"] ' . $recordContainer));
     $result['unknown'] = ScheduleParser::parseDay($crawler->filter('div[class="' . $classDay . 'unknown clearfix"] ' . $recordContainer));
     return $result;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:18,代碼來源:ScheduleParser.php

示例10: parse

 public static function parse($contents, $type)
 {
     $resultset = array();
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $menubar = true;
     //Filter into a set of tds from the source HTML table
     $mediaitems = $crawler->filterXPath('//div[@id="content"]/div/table/tr');
     foreach ($mediaitems as $item) {
         //tricky method to skip the menu bar which is also a <tr></tr>
         if ($menubar === true) {
             $menubar = false;
         } else {
             $resultset[] = self::parseRecord($item, $type);
         }
     }
     return $resultset;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:18,代碼來源:Upcoming.php

示例11: parseMessage

 public static function parseMessage($contents, $id)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent(str_replace('<br />', '', $contents), 'UTF-8');
     $message = new Messages();
     $message->setId((int) $id);
     # Action id of the message.
     # Example:
     # <input type="button" onclick="document.location='/mymessages.php?go=send&replyid=21193061&threadid=16092543&toname=Ratan12'" class="inputButton" value=" Reply ">
     $actionId = $crawler->filterXPath('//form[contains(@action,"delete")]/input[@name="id"]');
     $message->setActionId((int) $actionId->attr('value'));
     # Thread id of the message.
     # Example:
     # <a href="?go=read&id=0000000&threadid=00000000">
     $threadId = $crawler->filterXPath('//div/input[contains(@value,"Reply")]');
     $threadId = $threadId->attr('onclick');
     if (preg_match('/threadid=([\\d]*)/', $threadId, $threadMatches)) {
         $message->setThreadId((int) $threadMatches[1]);
     }
     # Username of the sender.
     # Example:
     # <a href="http://myanimelist.net/profile/ratan12">ratan12</a>
     $message->setUsername($crawler->filterXPath('//td[@class="dialog-text"]/h2/a')->text());
     # Time of the received message.
     # Example:
     # <small>50 minutes ago</small>
     $time = $crawler->filterXPath('//td[@class="dialog-text"]/div[contains(@class,"lightLink")]');
     if (count($time) > 0) {
         $message->setTime($time->text());
     }
     # Subject.
     # Example:
     # <div style="margin-bottom: 4px; font-weight: bold;">re: coolmessage</div>
     $messageSubject = $crawler->filterXPath('//td[@class="dialog-text"]/div[contains(@class,"fw-b")]')->text();
     $message->setSubject($messageSubject);
     # Message.
     $messageText = $crawler->filterXPath('//td[@class="dialog-text"]');
     if (preg_match('/Test Test<\\/div>(.*?)<div/s', $messageText->html(), $messageBody)) {
         $message->setMessage($messageBody[1]);
     }
     return $message;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:42,代碼來源:MessagesParser.php

示例12: parse

 public static function parse($contents)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $items = $crawler->filter('td[style="padding-left: 5px;"] table[width="100%"]');
     //Bypass Undefined variable error.
     $staff = null;
     $characters = null;
     foreach ($items as $item) {
         //Bypass to determine if the last table contains the staff members
         $crawler = new Crawler($item);
         if ($crawler->filter('td[width="27"]')->count() != 1) {
             $staffitems = $crawler->children();
             foreach ($staffitems as $staffitem) {
                 $staff[] = self::parseStaff($staffitem);
             }
         } else {
             $characters[] = self::parseCharacters($crawler);
         }
     }
     return array('Characters' => $characters, 'Staff' => $staff);
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:22,代碼來源:CastParser.php

示例13: parseTopic

 public static function parseTopic($contents)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $topicitems = $crawler->filter('div[class="forum_border_around "]');
     foreach ($topicitems as $item) {
         $set[] = self::parseTopicDetails($item);
     }
     $pages = $crawler->filter('div[class="fl-r pb4"]')->text();
     if ($pages != '') {
         $result['pages'] = (int) substr($pages, strpos($pages, ' (') + 2, strpos($pages, ')'));
     } else {
         $result['pages'] = 1;
     }
     $result['list'] = $set;
     return $result;
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:17,代碼來源:ForumParser.php

示例14: removeLastItem

 /**
  * @param $content string
  *
  * @return string
  */
 private function removeLastItem($content)
 {
     $document = new \DOMDocument('1.0', \Yii::$app->charset);
     $crawler = new Crawler();
     $crawler->addHTMLContent($content, \Yii::$app->charset);
     $root = $document->appendChild($document->createElement('_root'));
     $crawler->rewind();
     $root->appendChild($document->importNode($crawler->current(), true));
     $domxpath = new \DOMXPath($document);
     $crawlerInverse = $domxpath->query(CssSelector::toXPath($this->widgetItem . ':last-child'));
     foreach ($crawlerInverse as $key => $elementToRemove) {
         $parent = $elementToRemove->parentNode;
         $parent->removeChild($elementToRemove);
     }
     $crawler->clear();
     $crawler->add($document);
     return $crawler->filter('body')->eq(0)->html();
 }
開發者ID:tolik505,項目名稱:yii2-related-form,代碼行數:23,代碼來源:RelatedFormWidget.php

示例15: removeItems

 /**
  * Clear HTML widgetBody. Required to work with zero or more items.
  *
  * @param string $content
  */
 private function removeItems($content)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($content, \Yii::$app->charset);
     $crawler->filter($this->widgetItem)->each(function ($nodes) {
         foreach ($nodes as $node) {
             $node->parentNode->removeChild($node);
         }
     });
     return $crawler->html();
 }
開發者ID:wbraganca,項目名稱:yii2-dynamicform,代碼行數:16,代碼來源:DynamicFormWidget.php


注:本文中的Symfony\Component\DomCrawler\Crawler::addHTMLContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。