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


PHP Crawler::clear方法代码示例

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


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

示例1: extract

 /**
  * @param string $url
  * @param array  $tags
  *
  * @return WatchLink
  */
 public function extract(string $url, array $tags) : WatchLink
 {
     $watchLink = new WatchLink();
     $watchLink->setUrl($url);
     $this->crawler->clear();
     $this->crawler->addHtmlContent($this->fetcher->fetch($url));
     $watchLink->setName($this->extractTitle());
     $watchLink->setDescription($this->extractDescription());
     $watchLink->setImage($this->extractImage());
     foreach ($tags as $tag) {
         $watchLink->addTag($this->tagRepository->findOrCreate($tag));
     }
     return $watchLink;
 }
开发者ID:un-zero-un,项目名称:Veilleur,代码行数:20,代码来源:WatchLinkMetadataExtractor.php

示例2: crawl

 /**
  * {@inheritDoc}
  */
 public function crawl($html)
 {
     $crawler = new Crawler();
     $crawler->clear();
     $crawler->addHtmlContent($html);
     $movieInfo = $crawler->filter('#overview-top')->each(function (Crawler $domCrawler) {
         $title = $domCrawler->filter('.header span')->first()->text();
         $year = $domCrawler->filter('.header span')->last()->text();
         return ['title' => $title, 'year' => $year, 'rating' => $domCrawler->filter('.star-box .giga-star ')->first()->text(), 'desc' => $domCrawler->filter('p.description')->text()];
     });
 }
开发者ID:najaram,项目名称:moviefetcher,代码行数:14,代码来源:ImdbParser.php

示例3: load

 /**
  * @param $html
  * @return array
  */
 public function load($html)
 {
     $metaTags = [];
     $this->crawler->clear();
     $this->crawler->addHtmlContent($html);
     $this->crawler->filter('meta')->each(function (Crawler $node) {
         $name = strtolower($node->attr('name'));
         $content = $node->attr('content');
         $metaTags[$name] = $content;
     });
     $links = [];
     $this->crawler->filter('a')->each(function (Crawler $link) use(&$links) {
         $rel = $link->attr('rel');
         if ('nofollow' === strtolower($rel)) {
             return false;
         }
         $links[] = $link->attr('href');
         return $link;
     });
     $this->links = array_unique($links);
     $this->metaTags = $metaTags;
     return ['links' => $this->links, 'meta' => $metaTags];
 }
开发者ID:vedebel,项目名称:sitemap,代码行数:27,代码来源:SymfonyDomCrawler.php

示例4: getPositionData

 /**
  * @param Position $position
  * @param string $content
  */
 public function getPositionData(Position $position, $content)
 {
     $crawler = new Crawler($content);
     $trs = $crawler->filter('#full-props-list tr');
     $data = [];
     if ($trs->count() > 0) {
         foreach ($trs as $tr) {
             $crawler->clear();
             $crawler->addNode($tr);
             $th = $crawler->filter('th');
             $td = $crawler->filter('td');
             if ($th->count() > 0 && $td->count() > 0) {
                 $data[trim($th->text())] = trim($td->text());
             }
         }
     }
     $position->setAttributes($data);
 }
开发者ID:apoberez,项目名称:myLaboratory,代码行数:22,代码来源:HotlineProvider.php

示例5: handle

 public function handle()
 {
     $this->jobLogInfo('dmm start');
     $crawler = new Crawler();
     $guzzle = new Guzzle(['timeout' => 10, 'cookies' => true]);
     $jar = new CookieJar();
     \App\Model\Dmm::all()->map(function ($dmm) use($guzzle, $jar, $crawler) {
         $html = $guzzle->get($dmm->href, ['cookies' => $jar])->getBody();
         $crawler->addHtmlContent($html);
         $crawler->filterXPath('//ul[@id="list"]/li/div[1]//p[@class="tmb"]/a')->each(function (Crawler $crawle) use($dmm) {
             $title = trim($crawle->text());
             $href = $crawle->attr('href');
             $img_url = $crawle->filterXPath('//span[1]/img')->attr('src');
             DmmList::add($dmm->id, $title, $href, $img_url);
             echo "{$href}\n";
         });
         $crawler->clear();
     });
     $this->jobLogInfo('crawl end');
 }
开发者ID:sdhou,项目名称:CrawlPush,代码行数:20,代码来源:Dmm.php

示例6: testClear

 public function testClear()
 {
     $doc = new \DOMDocument();
     $node = $doc->createElement('test');
     $crawler = new Crawler($node);
     $crawler->clear();
     $this->assertCount(0, $crawler, '->clear() removes all the nodes from the crawler');
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:8,代码来源:CrawlerTest.php

示例7: testClear

 public function testClear()
 {
     $crawler = new Crawler(new \DOMNode());
     $crawler->clear();
     $this->assertCount(0, $crawler, '->clear() removes all the nodes from the crawler');
 }
开发者ID:shegun-babs,项目名称:dakrush,代码行数:6,代码来源:CrawlerTest.php

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

示例9: setHtml

 /**
  * @param string $html
  */
 private function setHtml($html)
 {
     $this->crawler->clear();
     $this->crawler->addHtmlContent($html);
 }
开发者ID:advmaker,项目名称:LamantinParser,代码行数:8,代码来源:Parser.php


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