当前位置: 首页>>代码示例>>PHP>>正文


PHP HtmlDomParser::str_get_html方法代码示例

本文整理汇总了PHP中Sunra\PhpSimple\HtmlDomParser::str_get_html方法的典型用法代码示例。如果您正苦于以下问题:PHP HtmlDomParser::str_get_html方法的具体用法?PHP HtmlDomParser::str_get_html怎么用?PHP HtmlDomParser::str_get_html使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sunra\PhpSimple\HtmlDomParser的用法示例。


在下文中一共展示了HtmlDomParser::str_get_html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleGet

 /**
  * @inheritdoc
  */
 protected function handleGet()
 {
     $html = $this->getContent($this->sourceUrl);
     $json = @json_decode($html);
     if (!$json || !$json->success || !$json->table) {
         throw new \Exception('Unknown server error');
     }
     $html = $this->htmlParser->str_get_html($json->table);
     $tableTrs = $html->find('tbody > tr');
     $find = false;
     $tr = current($tableTrs);
     $result = null;
     while ($tr && !$find) {
         $a = $tr->find('td > a', 0);
         if ($a && strtolower($a->innertext) === 'usd') {
             $result = $this->findTdWithLargestValue($tr);
             $find = true;
         }
         $tr = next($tableTrs);
     }
     if ($find) {
         return ['value' => $result];
     }
     throw new \Exception('USD not found in server response');
 }
开发者ID:nikolaykovenko,项目名称:usd-course-graph,代码行数:28,代码来源:KursComUaBlackMarket.php

示例2: getMenu

 /**
  * Get Menu
  *
  * Returns a KNP Menu object, which can be traversed or rendered
  *
  * @param string  $markup    Content to get items fro $this->getItems($markup, $topLevel, $depth)m
  * @param int     $topLevel  Top Header (1 through 6)
  * @param int     $depth     Depth (1 through 6)
  * @return ItemInterface     KNP Menu
  */
 public function getMenu($markup, $topLevel = 1, $depth = 6)
 {
     // Setup an empty menu object
     $menu = $this->menuFactory->createItem('TOC');
     // Empty?  Do nothing.
     if (trim($markup) == '') {
         return [];
     }
     // Parse HTML
     $tagsToMatch = $this->determineHeaderTags($topLevel, $depth);
     $parsed = $this->domParser->str_get_html($markup);
     // Runtime exception for bad code
     if (!$parsed) {
         throw new RuntimeException("Could not parse HTML");
     }
     // Extract items
     // Initial settings
     $lastElem = $menu;
     // Do it...
     foreach ($parsed->find(implode(', ', $tagsToMatch)) as $element) {
         // Skip items without IDs
         if (!$element->id) {
             continue;
         }
         // Get the TagName and the level
         $tagName = $element->tag;
         $level = array_search(strtolower($tagName), $tagsToMatch) + 1;
         // Determine parent item which to add child
         if ($level == 1) {
             $parent = $menu;
         } elseif ($level == $lastElem->getLevel()) {
             $parent = $lastElem->getParent();
         } elseif ($level > $lastElem->getLevel()) {
             $parent = $lastElem;
             for ($i = $lastElem->getLevel(); $i < $level - 1; $i++) {
                 $parent = $parent->addChild('');
             }
         } else {
             //if ($level < $lastElem->getLevel())
             $parent = $lastElem->getParent();
             while ($parent->getLevel() > $level - 1) {
                 $parent = $parent->getParent();
             }
         }
         $lastElem = $parent->addChild($element->title ?: $element->plaintext, ['uri' => '#' . $element->id]);
     }
     return $menu;
 }
开发者ID:igorvbelousov,项目名称:toc,代码行数:58,代码来源:TocGenerator.php

示例3: aggregatePromoDataFromWeb

 private function aggregatePromoDataFromWeb()
 {
     $response = $this->getPage('http://auto.danawa.com/newcar/?Work=sales');
     $html = HtmlDomParser::str_get_html($response);
     $elements = $html->find('div.salesCont');
     $arrData = [];
     foreach ($elements as $element) {
         $brandName = $element->prev_sibling()->children(0)->children(0)->alt;
         $subElements = $element->find('dl.base dt');
         $arrModels = [];
         foreach ($subElements as $subElement) {
             $model = str_replace(['올 뉴 ', '더 뉴 ', '신형 ', 'All New ', 'All-New ', 'The New ', 'New '], '', $subElement->children(0)->plaintext);
             $origString = str_replace(['&nbsp;', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧'], '', $subElement->next_sibling()->children(0)->innertext);
             $tempString = str_replace([', <span', '.+ ', '정용', '지급 시', '무이자할부'], ['|<span', ' + ', '적용', '지급시', '무이자 할부'], $origString);
             $items = array_map('trim', array_map('strip_tags', explode('|', $tempString)));
             if (array_key_exists($model, $arrModels)) {
                 foreach ($items as $item) {
                     array_push($arrModels[$model], $item);
                 }
             } else {
                 $arrModels[$model] = $items;
             }
         }
         $arrData[$brandName] = $arrModels;
     }
     return $arrData;
 }
开发者ID:jinseokoh,项目名称:ask,代码行数:27,代码来源:UpdatePromos.php

示例4: generateHtml

 protected function generateHtml($source, $template, $refresh)
 {
     // Check that the source file is sane
     if (!file_exists($source)) {
         throw new \Exception("Unable to open source file: {$source}");
     }
     // Check that our template is sane, or set to the default one
     if (!$template) {
         $template = $this->app->defaultTemplate;
     }
     $templatePath = join(DIRECTORY_SEPARATOR, array($this->app->templatePath, basename($template)));
     $templateIndexPath = join(DIRECTORY_SEPARATOR, array($templatePath, 'index.html'));
     if (!file_exists($templateIndexPath)) {
         throw new \Exception("Unable to open template file: {$templateIndexPath}");
     }
     $style = $this->generateContent($templatePath, 'css');
     $links = $this->generateContent($templatePath, 'links');
     $templateContent = file_get_contents($templateIndexPath);
     $resumeContent = file_get_contents($source);
     // Process with Markdown, and then use SmartyPants to clean up punctuation.
     $resumeHtml = MarkdownExtra::defaultTransform($resumeContent);
     $resumeHtml = SmartyPants::defaultTransform($resumeHtml);
     // Construct the title for the html document from the h1 and h2 tags
     $simpleDom = HtmlDomParser::str_get_html($resumeHtml);
     $title = sprintf('%s | %s', $simpleDom->find('h1', 0)->innertext, $simpleDom->find('h2', 0)->innertext);
     // Render the Markdown into an html file with Mustache Templates
     $m = new \Mustache_Engine();
     $rendered = $m->render($templateContent, array('title' => $title, 'style' => $style, 'links' => $links, 'resume' => $resumeHtml, 'reload' => (bool) $refresh, 'refresh_rate' => $refresh));
     return $rendered;
 }
开发者ID:KartikPadmanabhan,项目名称:markdown-resume,代码行数:30,代码来源:HtmlCommand.php

示例5: doImport

 public function doImport()
 {
     $this->cachePath .= date("Y-m-d") . '/';
     if (is_readable($this->cachePath) === false) {
         mkdir($this->cachePath, 0755, true);
     }
     $this->cacheFile = md5($this->sepaUrl . $this->sepaPage . '-' . date("Y-m-d")) . '.dat';
     $this->client = new Client(['base_uri' => $this->sepaUrl, 'timeout' => 5.0]);
     if (file_exists($this->cachePath . $this->cacheFile) === false) {
         $response = $this->client->get($this->sepaPage);
         if ($response->getStatusCode() > 204) {
             echo "Can't fetch list \n";
             exit(1);
         }
         $content = $response->getBody();
         file_put_contents($this->cachePath . $this->cacheFile, $content);
     } else {
         $content = file_get_contents($this->cachePath . $this->cacheFile);
     }
     $components = [];
     $html = HtmlDomParser::str_get_html($content);
     foreach ($html->find('label[class=komponentelabela]') as $label) {
         if (count($label->children())) {
             $sepaId = $label->children(0)->attr['value'];
             $name = $label->children(1)->plaintext;
             $component = ['sepa_id' => intval($sepaId), 'name' => trim($name)];
             array_push($components, $component);
         }
     }
     return $components;
 }
开发者ID:NemanjaK,项目名称:meteoalarm,代码行数:31,代码来源:ImportComponents.php

示例6: loadArticle

 public function loadArticle()
 {
     $this->html = file_get_contents(cbURL($this->id));
     $dom = HtmlDomParser::str_get_html($this->html);
     $this->article['id'] = $this->id;
     $titleNode = $dom->find('h2#news_title', 0);
     if (!$titleNode) {
         throw new ErrorException('文章找不到了...');
     }
     $this->article['title'] = $titleNode->plaintext;
     $this->article['date'] = $dom->find('div.title_bar span.date', 0)->plaintext;
     $this->article['source'] = trim($dom->find('div.title_bar span.where', 0)->plaintext);
     $this->article['source'] = str_replace('稿源:', '', $this->article['source']);
     $sourceLinkNode = $dom->find('div.title_bar span.where a', 0);
     if ($sourceLinkNode) {
         $this->article['sourceLink'] = $dom->find('div.title_bar span.where a', 0)->href;
     }
     $this->article['intro'] = trim($dom->find('div.introduction', 0)->plaintext);
     $topicURL = $dom->find('div.introduction div a', 0)->href;
     preg_match('/topics\\/(\\d+)\\.htm/', $topicURL, $matches);
     $this->article['topicId'] = (int) $matches[1];
     $this->article['topicTitle'] = $dom->find('div.introduction div a img', 0)->title;
     $this->article['topicImage'] = $dom->find('div.introduction div a img', 0)->src;
     $content = $dom->find('section.article_content div.content', 0)->innertext;
     $content = String::tidy($content);
     $this->article['content'] = str_replace(' class="f_center"', '', $content);
     $this->article['author'] = trim($dom->find('span.author', 0)->plaintext, "[] ");
 }
开发者ID:undownding,项目名称:cnBeta1,代码行数:28,代码来源:CnbetaArticleFetcher.php

示例7: aggregateTrimData

 private function aggregateTrimData($id, $brand, $model)
 {
     $url = 'http://m.auto.danawa.com/auto/?Work=model&Model=' . $id;
     $response = $this->getPage($url);
     $html = HtmlDomParser::str_get_html($response);
     $elements = $html->find('ul.modelPrice');
     for ($i = 0; $i < count($elements); $i++) {
         $lists = $elements[$i]->find('li');
         foreach ($lists as $item) {
             $string = trim($item->innertext);
             preg_match('/.*?<!--(.*?)-->.*/msU', $string, $comments);
             $words = preg_replace('/\\s+/', '', trim($comments[1]));
             preg_match('/<div>([^<]+)<\\/div><div>([^<]+)<\\/div><div>([^<]+)<\\/div>/', $words, $tags);
             $fuel = $tags[1];
             $engine = $tags[2];
             $mileage = $tags[3];
             $trim1 = trim($item->find('div.name span label', 0)->plaintext);
             $trim2 = str_replace('&nbsp;', '', $trim1);
             $trim3 = str_replace(['럭셔리', '프리미엄', '인승'], ['Luxury', 'Premium', '-seater'], $trim2);
             $trim4 = str_replace(['디젤', 'Diessel'], 'Diesel', $trim3);
             $trim5 = preg_replace('/[^\\x20-\\x7e]/', '', $trim4);
             $trim6 = str_replace(['( )', '()'], '', $trim5);
             $trim7 = str_replace(['(Without 360 Camera)', '(Without 360 camera/Sunroof'], ['Without 360 Camera', 'Without 360 Camera/Sunroof'], $trim6);
             $trim8 = str_replace(['LIMITED', 'LIMTED', 'hybrid', 'convertible', ' roof', 'EXECUTIVE', 'SUPREME', 'F-SPORT', 'F SPORT', 'F Sport', 'pkg', 'road', 'style', 'w/'], ['Limited', 'Limited', 'Hybrid', 'Convertible', ' Roof', 'Executive', 'Supreme', 'F-Sport', 'F-Sport', 'F-Sport', 'PKG', 'Road', 'Style', 'With '], $trim7);
             $trim9 = preg_replace('/\\s+/', ' ', $trim8);
             $trim = str_replace(['3.8 AWD & (A/T)'], ['3.8 AWD (A/T)'], $trim9);
             $price = intval(str_replace(',', '', trim($item->find('div.price span', 0)->plaintext)));
             $vehicle = Trim::updateOrCreate(['danawa_id' => $id, 'brand' => $brand, 'model' => $model, 'trim' => $trim, 'fuel' => $fuel, 'engine' => $engine, 'mileage' => $mileage, 'price' => $price]);
         }
     }
 }
开发者ID:jinseokoh,项目名称:ask,代码行数:31,代码来源:UpdateTrims.php

示例8: getSellerName

 public function getSellerName($sellerId, $marketPlace = "A1PA6795UKMFR9")
 {
     $url = "http://www.amazon.de/gp/aag/main?ie=UTF8&marketplaceID=" . $marketPlace . "&orderID=&seller=" . $sellerId;
     //echo $url;
     $this->lastUrl = $url;
     $html = file_get_contents($url);
     $dom = HtmlDomParser::str_get_html($html);
     $sellerName = null;
     $rightColumn = $dom->find('.amabot_right', 0);
     $UlElement = $rightColumn->find('ul.aagLegalData', 0);
     if ($UlElement != null) {
         $LiElement = $UlElement->find('li.aagLegalRow', 0);
         if ($LiElement != null) {
             $LiElement->children(0)->innertext = "";
             $sellerName = $LiElement->plaintext;
         }
     } else {
         $pElement = $rightColumn->find('p', 0);
         $children = $pElement->children(0);
         if ($children) {
             $children->innertext = "";
         }
         $sellerName = $pElement->plaintext;
     }
     return $sellerName;
 }
开发者ID:sebastien-fauvel,项目名称:Amazon-Mws-Repricing,代码行数:26,代码来源:AmazonRestService.php

示例9: content

 public static function content(ContentBlockController $controller)
 {
     $content = $controller->getSearchableContent();
     $dom = new HtmlDomParser();
     $r = $dom->str_get_html($content, true, true, DEFAULT_TARGET_CHARSET, false);
     if (is_object($r)) {
         foreach ($r->find('concrete-picture') as $picture) {
             $fID = $picture->fid;
             $fo = File::getByID($fID);
             if (is_object($fo)) {
                 $tag = new AmpImg($fo);
                 $tag->alt($picture->alt);
                 $picture->outertext = (string) $tag;
             }
         }
         foreach ($r->find('img') as $img) {
             $tag = new Element('amp-img');
             $tag->alt($img->alt);
             $tag->src($img->src);
             $tag->height($img->height);
             $tag->width($img->width);
             $img->outertext = (string) $tag;
         }
         foreach ($r->find('*[style]') as $element) {
             $element->removeAttribute('style');
         }
         $content = (string) $r->restore_noise($r);
     }
     $content = LinkAbstractor::translateFrom($content);
     return $content;
 }
开发者ID:hissy,项目名称:concrete5-amp,代码行数:31,代码来源:Converter.php

示例10: doImport

 public function doImport()
 {
     if (file_exists($this->cachePath . $this->cacheFile) === false) {
         $response = $this->client->get($this->sepaPage);
         if ($response->getStatusCode() > 204) {
             echo "Can't fetch list \n";
             exit(1);
         }
         $content = $response->getBody();
         file_put_contents($this->cachePath . $this->cacheFile, $content);
     } else {
         $content = file_get_contents($this->cachePath . $this->cacheFile);
     }
     $nodes = [];
     $html = HtmlDomParser::str_get_html($content);
     foreach ($html->find('tr') as $row) {
         if (count($row->children()) === 7) {
             $rowId = $row->children(0)->plaintext;
             $code = $row->children(1)->plaintext;
             $name = trim($row->children(3)->plaintext);
             $network = $row->children(4)->plaintext;
             $type = $row->children(5)->plaintext;
             //get sepa cms ID
             preg_match("/stanica=([\\d]+)/", $row->children(3)->innertext, $matches);
             if (isset($matches[1]) === true && is_numeric($matches[1]) && intval($matches[1]) > 0) {
                 $sepaId = $matches[1];
                 $node = ['eoi_code' => trim($code), 'name' => trim($name), 'network' => trim($network), 'type' => trim($type), 'sepa_id' => intval($sepaId)];
                 array_push($nodes, $node);
             }
         }
     }
     return $nodes;
 }
开发者ID:NemanjaK,项目名称:meteoalarm,代码行数:33,代码来源:ImportAllStations.php

示例11: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->app = $this->getApplication();
     $source = $input->getArgument('source');
     $destination = rtrim($input->getArgument('destination'), DIRECTORY_SEPARATOR);
     $template = $input->getOption('template');
     $pdfSource = join(DIRECTORY_SEPARATOR, array($destination, '.tmp_pdf_source.html'));
     $destFilename = join(DIRECTORY_SEPARATOR, array($destination, pathinfo($source, PATHINFO_FILENAME) . '.pdf'));
     // Make sure we've got out converter available
     exec('wkhtmltopdf -V', $results, $returnVal);
     if ($returnVal) {
         $output->writeln("\n<error>Error:</error> Unable to locate wkhtmltopdf.\n" . "  Please make sure that it is installed and available in " . "your path. \n  For installation help, please read: " . "https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF \n\n", $this->app->outputFormat);
         return false;
     }
     $rendered = $this->generateHtml($source, $template, false);
     // The pdf needs some extra css rules, and so we'll add them here
     // to our html document
     $simpleDom = HtmlDomParser::str_get_html($rendered);
     $body = $simpleDom->find('body', 0);
     $body->class = $body->class . ' pdf';
     $rendered = (string) $simpleDom;
     // Save to a temp destination for the pdf renderer to use
     file_put_contents($pdfSource, $rendered);
     // Process the document with wkhtmltopdf
     exec('wkhtmltopdf ' . $pdfSource . ' ' . $destFilename);
     // Unlink the temporary file
     unlink($pdfSource);
     $output->writeln(sprintf("Wrote pdf resume to: <info>%s</info>", $destFilename), $this->app->outputFormat);
     return true;
 }
开发者ID:KartikPadmanabhan,项目名称:markdown-resume,代码行数:30,代码来源:PdfCommand.php

示例12: exec

 /**
  * @param string $text
  * @param string $selector
  * @return array
  */
 public static function exec($text, $selector)
 {
     $document = HtmlDomParser::str_get_html($text);
     return array_map(function ($element) {
         return $element->innertext;
     }, $document->find($selector));
 }
开发者ID:AgenceStratis,项目名称:migrator,代码行数:12,代码来源:DocumentProcessor.php

示例13: execute

 /**
  * Execute the "missing" command
  *
  * @param  InputInterface $input Input object
  * @param  OutputInterface $output Output object
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->verbose = $input->getOption('verbose');
     $changelog = file_get_contents('http://php.net/ChangeLog-5.php');
     // Get our current checks
     $json = json_decode(file_get_contents(__DIR__ . '/../../../Psecio/Versionscan/checks.json'));
     $checksList = [];
     foreach ($json->checks as $check) {
         if (!in_array($check->cveid, $checksList)) {
             $checksList[] = $check->cveid;
         }
     }
     // Parse the changelog into versions
     preg_match_all('#<section class="version" id="([0-9\\.]+)">(.+?)</section>#ms', $changelog, $matches);
     $cveIdList = [];
     $fixVersions = [];
     $results = [];
     // print_r($matches);
     foreach ($matches[0] as $index => $match) {
         $versionId = $matches[1][$index];
         // see if we have any CVEs
         if (strstr($match, 'CVE') === false) {
             continue;
         }
         // Extract our CVEs
         preg_match_all('/CVE-[0-9]+-[0-9]+/', $match, $cveList);
         // @TODO limit it down to just five for throttling's sake
         $cveList[0] = array_slice($cveList[0], 0, 1);
         // print_r($cveList);
         foreach ($cveList[0] as $cveId) {
             if (in_array($cveId, $checksList) === true) {
                 continue;
             }
             $cveIdList[] = $cveId;
             $cveDetail = $this->getCveDetail($cveId, $output);
             if ($cveDetail === false) {
                 continue;
             }
             $dom = HtmlDomParser::str_get_html($cveDetail);
             $cveScore = $dom->find('div.cvssbox')[0]->plaintext;
             $cveSummary = explode("\n", trim($dom->find('div.cvedetailssummary')[0]->plaintext))[0];
             $output->writeLn('(' . $cveScore . ') fixed in ' . $versionId);
             if (!isset($fixVersions[$cveId])) {
                 $fixVersions[$cveId] = ['threat' => $cveScore, 'cveid' => $cveId, 'summary' => trim($cveSummary), 'fixVersions' => ['base' => []]];
             }
             $fixVersions[$cveId]['fixVersions']['base'][] = $versionId;
         }
     }
     if (empty($fixVersions)) {
         $output->writeLn('No missing versions/CVEs detected');
     } else {
         $jsonOutput = json_encode(array_values($fixVersions), JSON_PRETTY_PRINT);
         echo $jsonOutput . "\n\n";
     }
     if ($this->verbose === true) {
         $output->writeLn('Missing records found: ' . count($fixVersions));
     }
 }
开发者ID:psecio,项目名称:versionscan,代码行数:64,代码来源:MissingCommand.php

示例14: parseLists

 /**
  * 分析成績列表.
  *
  * @param string $content
  * @return array
  */
 protected function parseLists($content)
 {
     $rows = HtmlDomParser::str_get_html($content)->find('table table', 0)->find('tr[bgcolor!="#4d6eb2"]');
     $result = [];
     foreach ($rows as $row) {
         $result[] = ['name' => trim($row->children(0)->plaintext), 'value' => trim($row->children(4 === count($row->children) ? 2 : 1)->plaintext)];
     }
     return $result;
 }
开发者ID:BePsvPT,项目名称:CCU-Plus,代码行数:15,代码来源:Grade.php

示例15: boc_tach_noi_dung_bai_viet

 public function boc_tach_noi_dung_bai_viet($url)
 {
     $content = $this->lay_noi_dung($url);
     $html = HtmlDomParser::str_get_html($content);
     $noi_dung = $html->find('.the-article-summary', 0)->outertext;
     $noi_dung .= $html->find('.the-article-body', 0)->outertext;
     $noi_dung .= $html->find('.the-article-credit', 0)->outertext;
     return $noi_dung;
 }
开发者ID:lehoikma,项目名称:Larave-4.2,代码行数:9,代码来源:LayTinTucZing.php


注:本文中的Sunra\PhpSimple\HtmlDomParser::str_get_html方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。