diff --git a/Adapter/Crawler/SymfonyCrawler.php b/Adapter/Crawler/SymfonyCrawler.php index 7ee2376..d71603a 100644 --- a/Adapter/Crawler/SymfonyCrawler.php +++ b/Adapter/Crawler/SymfonyCrawler.php @@ -58,7 +58,7 @@ public function isOk() */ public function get($cssSelector) { - if (class_exists('Symfony\\Component\\CssSelector\\CssSelector')) { + if (class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) { return $this->filter($cssSelector); } diff --git a/Model/GoogleEngine.php b/Model/GoogleEngine.php index 419f617..59ec575 100644 --- a/Model/GoogleEngine.php +++ b/Model/GoogleEngine.php @@ -30,6 +30,8 @@ class GoogleEngine implements SearchEngineInterface private $name; private $scrapper; + const LINK_SELECTOR = "#res div.g h3 > a"; + public function __construct(ScrapperInterface $scrapper, CrawlerInterface $crawler, $name = null, $locale = null) { $this->crawler = $crawler; @@ -74,7 +76,7 @@ public function getWebsites($needle, $limit) $content = $this->scrapper->get($url); $crawler = $this->crawler->setContent($content); - $links = $crawler->get('#res li.g > h3 > a'); + $links = $crawler->get(self::LINK_SELECTOR); $websites = new WebsiteCollection(); @@ -95,7 +97,7 @@ public function getPosition($needle, WebsiteInterface $website) $url = $this->getRootUrl()."q=$needle&gbv=1&num=200"; $crawler = $this->crawler->setContent($this->scrapper->get($url)); - $links = $crawler->get('#res li.g > h3 > a'); + $links = $crawler->get(self::LINK_SELECTOR); foreach ($links as $position => $link) { $fullLocation = $link->getAttribute('href'); @@ -118,7 +120,7 @@ public function getBacklinks(WebsiteInterface $website) $url = $this->getRootUrl().'q=link:"'. $websiteLocation . '"-site:'. $websiteLocation .'&num=100'; $crawler = $this->crawler->setContent($this->scrapper->get($url)); - $links = $crawler->get('#res li.g > h3 > a'); + $links = $crawler->get(self::LINK_SELECTOR); foreach ($links as $position => $link) { $fullLocation = $link->getAttribute('href'); diff --git a/Tests/Fixtures/google.html b/Tests/Fixtures/google.html index 154b13f..a09d6cd 100644 --- a/Tests/Fixtures/google.html +++ b/Tests/Fixtures/google.html @@ -1,99 +1,359 @@ -Google
Si vous utilisez un lecteur d'écran, cliquez ici pour désactiver la recherche instantanée Google.
Champs masqués
Dites "Ok Google" pour lancer une recherche vocale.

Faites une recherche sans avoir à lever le petit doigt. Il vous suffit de dire "Ok Google" pour qu'une recherche sur les mots que vous énoncez ensuite soit lancée.

En savoir plus
+Google
Dites "Ok Google" pour lancer une recherche vocale.

Faites une recherche sans avoir à lever le petit doigt. Il vous suffit de dire "Ok Google" pour qu'une recherche sur les mots que vous énoncez ensuite soit lancée.

En savoir plus
\ No newline at end of file diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index b7022dd..228b297 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -61,7 +61,7 @@ public function testGoogleSearchReturnWebsiteCollection() public function testGetPositionOnWebsiteReturnInteger() { - $location = 'http://www.google.fr'; + $location = 'https://www.google.fr'; $content = file_get_contents('./Tests/Fixtures/google.html'); $website = new Website($this->crawler, $content, $location); $googleEngine = new GoogleFranceEngine($this->scrapper, $this->crawler); @@ -72,11 +72,11 @@ public function testGetPositionOnWebsiteReturnInteger() public function testGetBacklinksReturnArrayOfLinks() { - $location = 'http://www.google.fr'; + $location = 'https://www.google.fr'; $content = file_get_contents('./Tests/Fixtures/google.html'); $googleEngine = new GoogleFranceEngine($this->scrapper, $this->crawler); $website = new Website($this->crawler, $content, $location); - $this->assertEquals(100, count($googleEngine->getBacklinks($website))); + $this->assertGreaterThan(30, count($googleEngine->getBacklinks($website))); } } diff --git a/composer.json b/composer.json index 27504ac..72bb326 100644 --- a/composer.json +++ b/composer.json @@ -7,14 +7,17 @@ "authors": [ { "name": "Mickaël Andrieu", - "email": "mickael.andrieu@hotmail.fr" + "email": "mickael.andrieu@solvolabs.com" } ], "require": { - "php": ">=5.4.4", + "php": ">=5.6", "linclark/microdata-php": "2.0.2", - "symfony/css-selector": "^2.3|^3.0", - "symfony/dom-crawler": "^2.3|^3.0" + "symfony/css-selector": "~3.3", + "symfony/dom-crawler": "~3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" }, "suggest": { "ext-curl": "For usage of Curl adapter"