Commit 750acf42 authored by Karl's avatar Karl

Die Parser die Json oder XML nutzen geben jetzt wenn das initiale lesen...

Die Parser die Json oder XML nutzen geben jetzt wenn das initiale lesen fehlschlägt lediglich einen log aus statt abzustürzen
parent c76c7c35
......@@ -49,7 +49,6 @@ class Allesklar extends Searchengine
} catch (\InvalidArgumentException $e) {
}
});
}
......
......@@ -16,9 +16,7 @@ class Bing extends Searchengine
public function loadResults($result)
{
try
{
try {
$crawler = new Crawler($result);
$crawler->filter('ol#b_results > li.b_algo')->each(function (Crawler $node, $i) {
$title = $node->filter('li h2 > a')->text();
......
......@@ -19,13 +19,12 @@ class Europeana extends Searchengine
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$results = $content->items;
foreach ($results as $result) {
if (isset($result->edmPreview)) {
......@@ -56,8 +55,16 @@ class Europeana extends Searchengine
public function getNext(\App\MetaGer $metager, $result)
{
$start = ($metager->getPage()) * 10 + 1;
$content = json_decode($result);
$start = ($metager->getPage()) * 10 + 1;
try {
$content = json_decode($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
if ($start > $content->totalResults) {
return;
}
......
......@@ -19,9 +19,9 @@ class Flickr extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
......@@ -56,7 +56,8 @@ class Flickr extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
......
......@@ -19,13 +19,12 @@ class Openclipart extends Searchengine
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$results = $content->payload;
foreach ($results as $result) {
$title = $result->title;
......@@ -50,7 +49,15 @@ class Openclipart extends Searchengine
public function getNext(\App\MetaGer $metager, $result)
{
$content = json_decode($result);
try {
$content = json_decode($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
if ($content->info->current_page > $content->info->pages) {
return;
}
......
......@@ -19,9 +19,9 @@ class Overture extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
......@@ -70,7 +70,11 @@ class Overture extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$nextArgs = $content->xpath('//Results/NextArgs');
if (isset($nextArgs[0])) {
......
......@@ -19,7 +19,8 @@ class Pixabay extends Searchengine
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
......@@ -50,8 +51,16 @@ class Pixabay extends Searchengine
public function getNext(\App\MetaGer $metager, $result)
{
$page = $metager->getPage() + 1;
$content = json_decode($result);
$page = $metager->getPage() + 1;
try {
$content = json_decode($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
if ($page * 20 > $content->total) {
return;
}
......
......@@ -19,13 +19,12 @@ class Radiobrowser extends Searchengine
try {
$content = json_decode($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid json string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
foreach ($content as $result) {
$title = $result->name;
$link = $result->homepage;
......
......@@ -19,12 +19,13 @@ class Yandex extends Searchengine
try {
$content = simplexml_load_string($result);
} catch (\Exception $e) {
abort(500, "$result is not a valid xml string");
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$results = $content;
try {
$results = $results->xpath("//yandexsearch/response/results/grouping/group");
......@@ -56,13 +57,17 @@ class Yandex extends Searchengine
{
# Wir müssen herausfinden, ob es überhaupt noch weitere Ergebnisse von Yandex gibt:
try {
$content = simplexml_load_string($result);
$resultCount = intval($content->xpath('//yandexsearch/response/results/grouping/found[@priority="all"]')[0]->__toString());
$pageLast = $content->xpath('//yandexsearch/response/results/grouping/page')[0];
$pageLast = intval($pageLast["last"]->__toString());
$content = simplexml_load_string($result);
} catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return;
}
$resultCount = intval($content->xpath('//yandexsearch/response/results/grouping/found[@priority="all"]')[0]->__toString());
$pageLast = $content->xpath('//yandexsearch/response/results/grouping/page')[0];
$pageLast = intval($pageLast["last"]->__toString());
if (count($this->results) <= 0 || $pageLast >= $resultCount) {
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment