public function parseItem(GoogleDom $googleDOM, \DOMNode $node) { return new BaseResult(AdwordsResultType::SHOPPING_GROUP_PRODUCT, ['title' => function () use($googleDOM, $node) { $aTag = $googleDOM->getXpath()->query(Css::toXPath('.pla-unit-title-link'), $node)->item(0); if (!$aTag) { return null; } return $aTag->nodeValue; }, 'url' => function () use($node, $googleDOM) { $aTag = $googleDOM->getXpath()->query(Css::toXPath('.pla-unit-title-link'), $node)->item(0); if (!$aTag) { return $googleDOM->getUrl()->resolve('/'); } return $googleDOM->getUrl()->resolveAsString($aTag->getAttribute('href')); }, 'image' => function () use($node, $googleDOM) { $imgTag = $googleDOM->getXpath()->query(Css::toXPath('.pla-unit-img-container-link img'), $node)->item(0); if (!$imgTag) { return null; } return $imgTag->getAttribute('src'); }, 'target' => function () use($node, $googleDOM) { $aTag = $googleDOM->getXpath()->query(Css::toXPath('div._mC span.a'), $node)->item(0); if (!$aTag) { return null; } return $aTag->nodeValue; }, 'price' => function () use($node, $googleDOM) { $priceTag = $googleDOM->getXpath()->query(Css::toXPath('._QD._pvi'), $node)->item(0); if (!$priceTag) { return null; } return $priceTag->nodeValue; }]); }
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)); }
/** * @param GoogleDom $googleDom * @return CompositeResultSet */ public function parse(GoogleDom $googleDom) { $parsers = [new AdwordsSectionParser(Css::toXPath('div#tads li.ads-ad, div#tvcap ._oc'), AdwordsResultType::SECTION_TOP), new AdwordsSectionParser("descendant::div[@id = 'bottomads']//li[@class='ads-ad']", AdwordsResultType::SECTION_BOTTOM)]; $resultsSets = new CompositeResultSet(); foreach ($parsers as $parser) { /* @var $parser \Serps\SearchEngine\Google\Parser\Evaluated\AdwordsSectionParser */ $resultsSets->addResultSet($parser->parse($googleDom)); } return $resultsSets; }