本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::html方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::html方法的具体用法?PHP Crawler::html怎么用?PHP Crawler::html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DomCrawler\Crawler
的用法示例。
在下文中一共展示了Crawler::html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* @param Crawler $node
*
* @return array
*/
protected function parse(Crawler $node)
{
$title = explode(' - ', $node->html());
// Get the changes
$nodes = $node->nextAll()->filterXPath('h3[preceding-sibling::h2[1][.="' . $node->html() . '"]]');
$changes = (new ChangesRetriever($nodes))->retrieve();
return ['name' => $title[0], 'date' => isset($title[1]) ? $title[1] : null, 'changes' => $changes];
}
示例2: setLaundryState
public function setLaundryState(&$laundryPlace)
{
$user = 'youruser';
$pass = 'yourpassword';
try {
$client = new Client($laundryPlace['url']);
$request = $client->get('/LaundryState', [], ['auth' => [$user, $pass, 'Digest'], 'timeout' => 1.5, 'connect_timeout' => 1.5]);
$response = $request->send();
$body = $response->getBody();
libxml_use_internal_errors(true);
$crawler = new Crawler();
$crawler->addContent($body);
foreach ($crawler->filter('img') as $img) {
$resource = $img->getAttribute('src');
$img->setAttribute('src', 'http://129.241.126.11/' . trim($resource, '/'));
}
$crawler->addHtmlContent('<h1>foobar</h1>');
//'<link href="http://129.241.126.11/pic/public_n.css" type="text/css">');
$laundryPlace['html'] = $crawler->html();
libxml_use_internal_errors(false);
preg_match_all('/bgColor=Green/', $body, $greenMatches);
preg_match_all('/bgColor=Red/', $body, $redMatches);
$laundryPlace['busy'] = count($redMatches[0]);
$laundryPlace['available'] = count($greenMatches[0]);
} catch (\Exception $e) {
$laundryPlace['available'] = self::NETWORK_ERROR;
$laundryPlace['busy'] = self::NETWORK_ERROR;
$laundryPlace['html'] = self::NETWORK_ERROR;
}
}
示例3: getEventArrayFromResponse
/**
* @param Crawler $crawler
* @return mixed
*/
private function getEventArrayFromResponse(Crawler $crawler)
{
$html = $crawler->html();
$parts = explode(DefaultController::RESPONSE_BOUNDARY, $html);
$event = unserialize($parts[1]);
return $event;
}
示例4: onRenderAdminProductCategoryEditBefore
public function onRenderAdminProductCategoryEditBefore(FilterResponseEvent $event)
{
$app = $this->app;
$request = $event->getRequest();
$response = $event->getResponse();
$id = $request->attributes->get('id');
// DomCrawlerにHTMLを食わせる
$html = $response->getContent();
$crawler = new Crawler($html);
$CategoryContent = $app['category_content.repository.category_content']->find($id);
if (is_null($CategoryContent)) {
$CategoryContent = new \Plugin\CategoryContent\Entity\CategoryContent();
}
$form = $app['form.factory']->createBuilder('admin_category')->getForm();
$form->get('content')->setData($CategoryContent->getContent());
$form->handleRequest($request);
$twig = $app->renderView('CategoryContent/Resource/template/Admin/category.twig', array('form' => $form->createView()));
$oldCrawler = $crawler->filter('form')->first();
// DomCrawlerからHTMLを吐き出す
$html = $crawler->html();
$oldHtml = '';
$newHtml = '';
if (count($oldCrawler) > 0) {
$oldHtml = $oldCrawler->html();
$newHtml = $oldHtml . $twig;
}
$html = str_replace($oldHtml, $newHtml, $html);
$response->setContent($html);
$event->setResponse($response);
}
示例5: getPrices
/**
* @param Crawler $block
* @return array|null
*/
public function getPrices(Crawler $block)
{
$results = preg_match_all('/(\\d+(\\.\\d{1,}|,\\d{1,})?) *(€|Eur|eur|EUR)/i', $block->html(), $matches);
if ($results == 0) {
return null;
}
return $matches[0];
}
示例6: getScopeContent
/**
* parse itemscope itemprop and hydrate given card
*
* scope come from itemref, set isItemRef to true
*
* @param Crawler $node
* @param iCard $card
* @param boolean $isItemref
*/
public function getScopeContent(Crawler $node, CardInterface $card, $isItemref = false)
{
$content = $node->html();
$cr = new Crawler($content);
$cr->filter('[itemprop]')->each(function ($node) use($card, $isItemref) {
$this->setCardProperty($node, $card, $isItemref);
});
}
示例7: parse
/**
* @param Crawler $node
*
* @return array
*/
protected function parse(Crawler $node)
{
$key = strtolower($node->html());
if (!$key) {
return;
}
$lines = (new LineRetriever($node->nextAll()->first()->filter('li')))->retrieve();
return ['section' => $key, 'changes' => $lines];
}
示例8: matches
/**
* Check if the source or text is found within the element in the given crawler.
*
* @param \Symfony\Component\DomCrawler\Crawler|string $crawler
* @return bool
*/
public function matches($crawler)
{
$elements = $this->crawler($crawler)->filter($this->element);
$pattern = $this->getEscapedPattern($this->text);
foreach ($elements as $element) {
$element = new Crawler($element);
if (preg_match("/{$pattern}/i", $element->html())) {
return true;
}
}
return false;
}
示例9: calculatePageSizeInKb
/**
* @param string $html
*
* @return string
*/
protected function calculatePageSizeInKb(Crawler $crawler)
{
try {
$html = $crawler->html();
} catch (\InvalidArgumentException $e) {
return self::NOT_AVAILABLE;
}
$size = mb_strlen($html) / 1024;
if (is_numeric($size)) {
$floatSize = (double) $size;
return round($floatSize, 2) . 'kb';
}
}
示例10: proxyImage
public function proxyImage(Twig_Environment $twig, $content)
{
if ($this->getEnabled() === false) {
return $content;
}
$crawler = new Crawler($content);
foreach ($crawler->filter('img') as $image) {
$hashedImageUrl = hash_hmac(self::$hashingAlgorithm, self::$salt . $image->getAttribute('src'), self::$secret);
$hexedImageUrl = bin2hex($image->getAttribute('src'));
$proxiedImageUrl = self::$serverAddress . "/" . $hashedImageUrl . "/" . $hexedImageUrl;
$image->setAttribute('src', $proxiedImageUrl);
}
return $crawler->html();
}
示例11: replaceImages
public function replaceImages(Flyer $flyer)
{
$flyer_html = $flyer->getHtml();
$crawler = new Crawler();
$crawler->addHtmlContent($flyer_html);
foreach ($crawler->filter('img') as $domElement) {
$attr_src = $domElement->getAttribute('src');
if (!$this->validateURL($attr_src)) {
$result = $this->utilsBusiness->upladImage($attr_src, 'flyers');
$domElement->setAttribute('src', $result['url']);
}
}
$flyer->setHtml($crawler->html());
$this->saveData($flyer);
return $flyer;
}
示例12: showRecommendProduct
public function showRecommendProduct(FilterResponseEvent $event)
{
$app = $this->app;
$id = $app['request']->attributes->get('id');
$Product = $app['eccube.repository.product']->find($id);
$RecommendProducts = $app['eccube.plugin.recommend.repository.recommend_product']->findAll();
if (count($RecommendProducts) > 0) {
$twig = $app->renderView('Recommend/View/recommend_product.twig', array('RecommendProducts' => $RecommendProducts));
$response = $event->getResponse();
$html = $response->getContent();
$crawler = new Crawler($html);
$oldElement = $crawler->filter('#main');
$oldHtml = $oldElement->html();
$newHtml = $oldHtml . $twig;
$html = $crawler->html();
$html = str_replace($oldHtml, $newHtml, $html);
$response->setContent($html);
$event->setResponse($response);
}
}
示例13: getHtml
/**
* EC-CUBEの受注マスター画面のHTMLを取得し、帳票関連項目を書き込む
*
* @param unknown $request
* @param unknown $response
* @param unknown $id
* @return mixed
*/
private function getHtml($request, $response, $id)
{
// 検索結果一覧の下部に帳票出力を追加する
// 受注管理-受注マスターのHTMLを取得し、DOM化
$crawler = new Crawler($response->getContent());
// [orm id="dropdown-form"]の最終項目に追加(レイアウトに依存(時間無いのでベタ))
$html = $crawler->html();
$parts = $this->app->renderView('OrderPdf/View/admin/order_pdf_menu.twig');
try {
// ※商品編集画面 idなりclassなりがきちんとつかないとDOMをいじるのは難しい
// また、[その他]メニューの中に入れ込もうとしたがJQUERYのイベントが動作するので不可
// = = = = = = = = =
// その他メニューに追加するバージョン
$form = $crawler->filter('#dropmenu .dropdown-menu')->last()->html();
$newForm = $form . $parts;
$html = str_replace($form, $newForm, $html);
} catch (\InvalidArgumentException $e) {
// no-op
}
return html_entity_decode($html);
}
示例14: onRenderProductsDetailBefore
/**
* フロント:商品詳細画面に商品レビューを表示します.
* @param FilterResponseEvent $event
*/
public function onRenderProductsDetailBefore(FilterResponseEvent $event)
{
// カート内でも呼ばれるためGETに限定
if ($event->getRequest()->getMethod() === 'GET') {
$app = $this->app;
$limit = $app['config']['review_regist_max'];
$id = $app['request']->attributes->get('id');
$Product = $app['eccube.repository.product']->find($id);
$Disp = $app['eccube.repository.master.disp']->find(\Eccube\Entity\Master\Disp::DISPLAY_SHOW);
$ProductReviews = $app['eccube.plugin.product_review.repository.product_review']->findBy(array('Product' => $Product, 'Status' => $Disp), array('create_date' => 'DESC'), $limit === null ? 5 : $limit);
$twig = $app->renderView('ProductReview/Resource/template/default/product_review.twig', array('id' => $id, 'ProductReviews' => $ProductReviews));
$response = $event->getResponse();
$html = $response->getContent();
$crawler = new Crawler($html);
$oldElement = $crawler->filter('#item_detail_area .item_detail');
$oldHtml = $oldElement->html();
$newHtml = $oldHtml . $twig;
$html = $crawler->html();
$html = str_replace($oldHtml, $newHtml, $html);
$response->setContent($html);
$event->setResponse($response);
}
}
示例15: addContentOnProductEdit
public function addContentOnProductEdit(FilterResponseEvent $event)
{
$app = $this->app;
$request = $event->getRequest();
$response = $event->getResponse();
$id = $request->attributes->get('id');
$html = $response->getContent();
$crawler = new Crawler($html);
$form = $app['form.factory']->createBuilder('admin_product')->getForm();
if ($id) {
$Product = $app['eccube.repository.product']->find($id);
} else {
$Product = new \Eccube\Entity\Product();
}
$RelatedProducts = $app['eccube.plugin.repository.related_product']->findBy(array('Product' => $Product));
$loop = 5 - count($RelatedProducts);
for ($i = 0; $i < $loop; $i++) {
$RelatedProduct = new \Plugin\RelatedProduct\Entity\RelatedProduct();
$RelatedProduct->setProductId($id)->setProduct($Product);
$RelatedProducts[] = $RelatedProduct;
}
$form->get('related_collection')->setData($RelatedProducts);
$form->handleRequest($request);
// 商品検索フォーム
$searchForm = $app['form.factory']->createBuilder('admin_search_product')->getForm();
$twig = $app->renderView('RelatedProduct/Resource/template/Admin/related_product.twig', array('form' => $form->createView()));
$modal = $app->renderView('RelatedProduct/Resource/template/Admin/modal.twig', array('searchForm' => $searchForm->createView()));
$oldElement = $crawler->filter('.accordion')->last();
if ($oldElement->count() > 0) {
$oldHtml = $oldElement->html();
$newHtml = $oldHtml . $twig;
$html = $crawler->html() . $modal;
$html = str_replace($oldHtml, $newHtml, $html);
$response->setContent($html);
$event->setResponse($response);
}
}