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


PHP PhpSimple\HtmlDomParser类代码示例

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


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

示例1: 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

示例2: fromHtml

 public static function fromHtml($html)
 {
     $dom = new HtmlDomParser();
     $r = $dom->str_get_html($html);
     $nodes = $r->childNodes();
     $node = $nodes[0];
     $element = new Element($node->tag);
     $element->class($node->class);
     $column = new static($element);
     return $column;
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:11,代码来源:Column.php

示例3: fromHtml

 public static function fromHtml($html)
 {
     $dom = new HtmlDomParser();
     $r = $dom->str_get_html($html);
     $nodes = $r->childNodes();
     $node = $nodes[0];
     $element = new Element($node->tag);
     foreach ($node->getAllAttributes() as $key => $value) {
         $element->setAttribute($key, $value);
     }
     $column = new static($element);
     return $column;
 }
开发者ID:digideskio,项目名称:concrete5,代码行数:13,代码来源:Column.php

示例4: getLayoutContainerHtmlObject

 public function getLayoutContainerHtmlObject()
 {
     $gf = $this->layout->getThemeGridFrameworkObject();
     if (is_object($gf)) {
         $dom = new HtmlDomParser();
         $r = $dom->str_get_html($gf->getPageThemeGridFrameworkRowStartHTML() . $gf->getPageThemeGridFrameworkRowEndHTML());
         $nodes = $r->childNodes();
         $node = $nodes[0];
         $element = new Element($node->tag);
         $element->id($node->id);
         $element->class($node->class);
         return $element;
     }
 }
开发者ID:hdk0016,项目名称:concrete5-1,代码行数:14,代码来源:ThemeGridFormatter.php

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例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: 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

示例12: 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

示例13: 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

示例14: getPrice

 public static function getPrice($url)
 {
     $parser = new HtmlDomParser();
     $dom = $parser->file_get_html($url);
     $price = $dom->find('div.pricelabel strong')[0]->plaintext;
     unset($dom);
     if (isset($price) && !empty($price)) {
         preg_match_all("/(\\d+)/", str_replace(" ", "", $price), $price);
         if (isset($price[0]) && !empty($price[0])) {
             return $price[0];
         } else {
             return "0";
         }
     } else {
         return "0";
     }
 }
开发者ID:Sywooch,项目名称:find-parser,代码行数:17,代码来源:RabotaOlx.php

示例15: getPresetContainerHtmlObject

 public function getPresetContainerHtmlObject()
 {
     $dom = new HtmlDomParser();
     $r = $dom->str_get_html($this->arrayPreset['container']);
     if (is_object($r)) {
         $nodes = $r->childNodes();
         $node = $nodes[0];
         if (is_object($node)) {
             $element = new Element($node->tag);
             $element->class($node->class);
         }
     }
     if (!isset($element)) {
         $element = new Element('div');
     }
     return $element;
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:17,代码来源:ThemeFormatter.php


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