public function parse(GoogleDom $googleDOM, \DomElement $node, IndexedResultSet $resultSet)
 {
     $item = ['title' => function () use($googleDOM, $node) {
         $aTag = $googleDOM->getXpath()->query('descendant::h3/a[2]', $node)->item(0);
         if (!$aTag) {
             return null;
         }
         return $aTag->nodeValue;
     }, 'url' => function () use($node, $googleDOM) {
         $aTag = $googleDOM->getXpath()->query('descendant::h3/a[2]', $node)->item(0);
         if (!$aTag) {
             return $googleDOM->getUrl()->resolve('/');
         }
         return $googleDOM->getUrl()->resolveAsString($aTag->getAttribute('href'));
     }, 'visurl' => function () use($node, $googleDOM) {
         $aTag = $googleDOM->getXpath()->query(Css::toXPath('div.ads-visurl>cite'), $node)->item(0);
         if (!$aTag) {
             return null;
         }
         return $aTag->nodeValue;
     }, 'description' => function () use($node, $googleDOM) {
         $aTag = $googleDOM->getXpath()->query(Css::toXPath('div.ads-creative'), $node)->item(0);
         if (!$aTag) {
             return null;
         }
         return $aTag->nodeValue;
     }];
     $resultSet->addItem(new BaseResult(AdwordsResultType::AD, $item));
 }
 public function parse(GoogleDom $dom, \DomElement $node, IndexedResultSet $resultSet)
 {
     $xPath = $dom->getXpath();
     $item = ['items' => function () use($node, $dom) {
         return [];
     }];
     $resultSet->addItem(new BaseResult(NaturalResultType::VIDEO_GROUP, $item));
 }
 public function parse(GoogleDom $googleDOM, \DomElement $group, IndexedResultSet $resultSet)
 {
     $item = ['news' => []];
     $xpathCards = "div/div[contains(concat(' ',normalize-space(@class),' '),' card-section ')]";
     $cardNodes = $googleDOM->getXpath()->query($xpathCards, $group);
     foreach ($cardNodes as $cardNode) {
         $item['news'][] = $this->parseItem($googleDOM, $cardNode);
     }
     $resultSet->addItem(new BaseResult(NaturalResultType::IN_THE_NEWS, $item));
 }
 public function parse(GoogleDom $dom, \DomElement $node, IndexedResultSet $resultSet)
 {
     $xpath = $dom->getXpath();
     /* @var $aTag \DOMElement */
     $aTag = $xpath->query("descendant::h3[@class='r'][1]//a", $node)->item(0);
     if ($aTag) {
         $title = $aTag->nodeValue;
         preg_match('/@([A-Za-z0-9_]{1,15})/', $title, $match);
         $data = ['title' => $title, 'url' => $aTag->getAttribute('href'), 'user' => $match[0]];
         $item = new BaseResult(NaturalResultType::TWEETS_CAROUSEL, $data);
         $resultSet->addItem($item);
     }
 }
 public function parse(GoogleDom $googleDOM, \DomElement $node, IndexedResultSet $resultSet)
 {
     $item = ['products' => function () use($googleDOM, $node) {
         $items = [];
         $xpathCards = Css::toXPath('.pla-unit');
         $productNodes = $googleDOM->getXpath()->query($xpathCards, $node);
         foreach ($productNodes as $productNode) {
             $items[] = $this->parseItem($googleDOM, $productNode);
         }
         return $items;
     }];
     $resultSet->addItem(new BaseResult(AdwordsResultType::SHOPPING_GROUP, $item));
 }
 public function parse(GoogleDom $googleDOM, \DomElement $node, IndexedResultSet $resultSet)
 {
     $item = ['images' => [], 'moreUrl' => function () use($node, $googleDOM) {
         $aTag = $googleDOM->getXpath()->query('descendant::div[@class="_Icb _kk _wI"]/a', $node)->item(0);
         if (!$aTag) {
             return $googleDOM->getUrl()->resolve('/');
         }
         return $googleDOM->getUrl()->resolveAsString($aTag->getAttribute('href'));
     }];
     // TODO: detect no image (google dom update)
     $imageNodes = $googleDOM->cssQuery('.rg_ul>div._ZGc a', $node);
     foreach ($imageNodes as $imgNode) {
         $item['images'][] = $this->parseItem($googleDOM, $imgNode);
     }
     $resultSet->addItem(new BaseResult(NaturalResultType::IMAGE_GROUP, $item));
 }
Example #7
0
 public function parse(GoogleDom $dom, \DomElement $node, IndexedResultSet $resultSet)
 {
     $xPath = $dom->getXpath();
     $item = ['localPack' => function () use($xPath, $node, $dom) {
         $localPackNodes = $xPath->query('descendant::div[@class="_gt"]', $node);
         $data = [];
         foreach ($localPackNodes as $localPack) {
             $data[] = new BaseResult(NaturalResultType::MAP_PLACE, $this->parseItem($localPack, $dom));
         }
         return $data;
     }, 'mapUrl' => function () use($xPath, $node, $dom) {
         $mapATag = $dom->cssQuery('#lu_map', $node)->item(0)->parentNode;
         if ($mapATag) {
             return $dom->getUrl()->resolveAsString($mapATag->getAttribute('href'));
         }
         return null;
     }];
     $resultSet->addItem(new BaseResult(NaturalResultType::MAP, $item));
 }
 public function parse(GoogleDom $dom, \DomElement $node, IndexedResultSet $resultSet)
 {
     $xpath = $dom->getXpath();
     $aTag = $xpath->query("descendant::h3[@class='r'][1]/a", $node)->item(0);
     if (!$aTag) {
         return false;
     }
     $destinationTag = $xpath->query("descendant::div[@class='f kv _SWb']/cite", $node)->item(0);
     $data = ['title' => $aTag->nodeValue, 'url' => $dom->getUrl()->resolveAsString($aTag->getAttribute('href')), 'destination' => $destinationTag ? $destinationTag->nodeValue : null, 'description' => null, 'videoLarge' => true, 'thumb' => null, 'videoCover' => function () use($dom, $node) {
         $imageTag = $dom->cssQuery('._ELb img', $node)->item(0);
         if ($imageTag) {
             return MediaFactory::createMediaFromSrc($imageTag->getAttribute('src'));
             // TODO 1p gif ?
         } else {
             return null;
         }
     }];
     $resultSet->addItem(new BaseResult([NaturalResultType::CLASSICAL_VIDEO, NaturalResultType::CLASSICAL], $data));
 }
 public function parse(GoogleDom $dom, \DomElement $node, IndexedResultSet $resultSet)
 {
     $data = $this->parseNode($dom, $node);
     $data['sitelinks'] = function () use($dom, $node) {
         $items = $dom->cssQuery('.nrgt tr.mslg>td>.sld', $node);
         $siteLinksData = [];
         foreach ($items as $item) {
             $siteLinksData[] = new BaseResult(NaturalResultType::CLASSICAL_SITELINK, ['title' => function () use($dom, $item) {
                 return $dom->cssQuery('h3.r a', $item)->item(0)->textContent;
             }, 'description' => function () use($dom, $item) {
                 return $dom->cssQuery('.st', $item)->item(0)->textContent;
             }, 'url' => function () use($dom, $item) {
                 return $dom->cssQuery('h3.r a', $item)->item(0)->getAttribute('href');
             }]);
         }
         return $siteLinksData;
     };
     $resultTypes = [NaturalResultType::CLASSICAL, NaturalResultType::CLASSICAL_LARGE];
     $item = new BaseResult($resultTypes, $data);
     $resultSet->addItem($item);
 }
 public function parse(GoogleDom $dom, \DomElement $node, IndexedResultSet $resultSet)
 {
     $data = $this->parseNode($dom, $node);
     $resultTypes = [NaturalResultType::CLASSICAL];
     // classical result can have a video thumbnail
     $thumb = $dom->getXpath()->query("descendant::g-img[@class='_ygd']/img", $node)->item(0);
     if ($thumb) {
         $resultTypes[] = NaturalResultType::CLASSICAL_ILLUSTRATED;
         $data['thumb'] = function () use($thumb) {
             if ($thumb) {
                 return MediaFactory::createMediaFromSrc($thumb->getAttribute('src'));
             } else {
                 return null;
             }
         };
     }
     $videoDuration = $dom->cssQuery('.vdur', $node);
     if ($videoDuration->length == 1) {
         $resultTypes[] = array_unshift($resultTypes, NaturalResultType::CLASSICAL_VIDEO);
         $data['videoLarge'] = false;
     }
     $item = new BaseResult($resultTypes, $data);
     $resultSet->addItem($item);
 }
 public function parse(GoogleDom $dom, \DOMElement $node, IndexedResultSet $resultSet)
 {
     $item = new BaseResult([NaturalResultType::ANSWER_BOX], $this->parseNode($dom, $node));
     $resultSet->addItem($item);
 }
 public function parse(GoogleDom $googleDOM, \DomElement $group, IndexedResultSet $resultSet)
 {
     $resultSet->addItem(new BaseResult(NaturalResultType::FLIGHTS, []));
 }
 /**
  * @param string $location the locations of the results (top, bottom, right)
  */
 public function __construct($location)
 {
     $this->location = $location;
     parent::__construct(1);
 }