From 4131161cde90010ea9b46856fa4f6a1b7ed37a5b Mon Sep 17 00:00:00 2001 From: Dominik Pfennig <dominik@suma-ev.de> Date: Thu, 7 Jul 2016 13:05:47 +0200 Subject: [PATCH] =?UTF-8?q?Yandex=20Parser=20eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/parserSkripte/Yandex.php | 53 ++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/app/Models/parserSkripte/Yandex.php b/app/Models/parserSkripte/Yandex.php index 92b7754f8..2a0366bdc 100644 --- a/app/Models/parserSkripte/Yandex.php +++ b/app/Models/parserSkripte/Yandex.php @@ -2,6 +2,7 @@ namespace app\Models\parserSkripte; use App\Models\Searchengine; +use Log; class Yandex extends Searchengine { @@ -14,22 +15,40 @@ class Yandex extends Searchengine public function loadResults ($result) { + $result = preg_replace("/\r\n/si", "", $result); + try { + $content = simplexml_load_string($result); + } catch (\Exception $e) { + abort(500, "$result is not a valid xml string"); + } - $title = ""; - $link = ""; - $anzeigeLink = $link; - $descr = ""; - - #die($result); - - /*$this->counter++; - $this->results[] = new \App\Models\Result( - $title, - $link, - $anzeigeLink, - $descr, - $this->gefVon, - $this->counter - );*/ + if(!$content) + { + return; + } + $results = $content; + try{ + $results = $results->xpath("//yandexsearch/response/results/grouping/group"); + } catch(\ErrorException $e) + { + return; + } + foreach($results as $result) + { + $title = strip_tags($result->{"doc"}->{"title"}->asXML()); + $link = $result->{"doc"}->{"url"}->__toString(); + $anzeigeLink = $link; + $descr = strip_tags($result->{"doc"}->{"headline"}->asXML()); + $this->counter++; + $this->results[] = new \App\Models\Result( + $this->engine, + $title, + $link, + $anzeigeLink, + $descr, + $this->gefVon, + $this->counter + ); + } } -} \ No newline at end of file +} -- GitLab