Skip to content
Snippets Groups Projects
Commit 038fb08c authored by Karl's avatar Karl
Browse files

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 5956c20a
No related branches found
No related tags found
1 merge request!1365Resolve "Filter Options for MetaGer"
...@@ -49,7 +49,6 @@ class Allesklar extends Searchengine ...@@ -49,7 +49,6 @@ class Allesklar extends Searchengine
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
} }
}); });
} }
......
...@@ -16,9 +16,7 @@ class Bing extends Searchengine ...@@ -16,9 +16,7 @@ class Bing extends Searchengine
public function loadResults($result) public function loadResults($result)
{ {
try {
try
{
$crawler = new Crawler($result); $crawler = new Crawler($result);
$crawler->filter('ol#b_results > li.b_algo')->each(function (Crawler $node, $i) { $crawler->filter('ol#b_results > li.b_algo')->each(function (Crawler $node, $i) {
$title = $node->filter('li h2 > a')->text(); $title = $node->filter('li h2 > a')->text();
......
...@@ -19,13 +19,12 @@ class Europeana extends Searchengine ...@@ -19,13 +19,12 @@ class Europeana extends Searchengine
try { try {
$content = json_decode($result); $content = json_decode($result);
} catch (\Exception $e) { } 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) { if (!$content) {
return; return;
} }
$results = $content->items; $results = $content->items;
foreach ($results as $result) { foreach ($results as $result) {
if (isset($result->edmPreview)) { if (isset($result->edmPreview)) {
...@@ -56,8 +55,16 @@ class Europeana extends Searchengine ...@@ -56,8 +55,16 @@ class Europeana extends Searchengine
public function getNext(\App\MetaGer $metager, $result) public function getNext(\App\MetaGer $metager, $result)
{ {
$start = ($metager->getPage()) * 10 + 1; $start = ($metager->getPage()) * 10 + 1;
$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 ($start > $content->totalResults) { if ($start > $content->totalResults) {
return; return;
} }
......
...@@ -19,9 +19,9 @@ class Flickr extends Searchengine ...@@ -19,9 +19,9 @@ class Flickr extends Searchengine
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { } 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) { if (!$content) {
return; return;
} }
...@@ -56,7 +56,8 @@ class Flickr extends Searchengine ...@@ -56,7 +56,8 @@ class Flickr extends Searchengine
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { } 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) { if (!$content) {
return; return;
......
...@@ -19,13 +19,12 @@ class Openclipart extends Searchengine ...@@ -19,13 +19,12 @@ class Openclipart extends Searchengine
try { try {
$content = json_decode($result); $content = json_decode($result);
} catch (\Exception $e) { } 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) { if (!$content) {
return; return;
} }
$results = $content->payload; $results = $content->payload;
foreach ($results as $result) { foreach ($results as $result) {
$title = $result->title; $title = $result->title;
...@@ -50,7 +49,15 @@ class Openclipart extends Searchengine ...@@ -50,7 +49,15 @@ class Openclipart extends Searchengine
public function getNext(\App\MetaGer $metager, $result) 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) { if ($content->info->current_page > $content->info->pages) {
return; return;
} }
......
...@@ -19,9 +19,9 @@ class Overture extends Searchengine ...@@ -19,9 +19,9 @@ class Overture extends Searchengine
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { } 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) { if (!$content) {
return; return;
} }
...@@ -70,7 +70,11 @@ class Overture extends Searchengine ...@@ -70,7 +70,11 @@ class Overture extends Searchengine
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { } 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'); $nextArgs = $content->xpath('//Results/NextArgs');
if (isset($nextArgs[0])) { if (isset($nextArgs[0])) {
......
...@@ -19,7 +19,8 @@ class Pixabay extends Searchengine ...@@ -19,7 +19,8 @@ class Pixabay extends Searchengine
try { try {
$content = json_decode($result); $content = json_decode($result);
} catch (\Exception $e) { } 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) { if (!$content) {
...@@ -50,8 +51,16 @@ class Pixabay extends Searchengine ...@@ -50,8 +51,16 @@ class Pixabay extends Searchengine
public function getNext(\App\MetaGer $metager, $result) public function getNext(\App\MetaGer $metager, $result)
{ {
$page = $metager->getPage() + 1; $page = $metager->getPage() + 1;
$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 ($page * 20 > $content->total) { if ($page * 20 > $content->total) {
return; return;
} }
......
...@@ -19,13 +19,12 @@ class Radiobrowser extends Searchengine ...@@ -19,13 +19,12 @@ class Radiobrowser extends Searchengine
try { try {
$content = json_decode($result); $content = json_decode($result);
} catch (\Exception $e) { } 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) { if (!$content) {
return; return;
} }
foreach ($content as $result) { foreach ($content as $result) {
$title = $result->name; $title = $result->name;
$link = $result->homepage; $link = $result->homepage;
......
...@@ -19,12 +19,13 @@ class Yandex extends Searchengine ...@@ -19,12 +19,13 @@ class Yandex extends Searchengine
try { try {
$content = simplexml_load_string($result); $content = simplexml_load_string($result);
} catch (\Exception $e) { } 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) { if (!$content) {
return; return;
} }
$results = $content; $results = $content;
try { try {
$results = $results->xpath("//yandexsearch/response/results/grouping/group"); $results = $results->xpath("//yandexsearch/response/results/grouping/group");
...@@ -56,13 +57,17 @@ class Yandex extends Searchengine ...@@ -56,13 +57,17 @@ class Yandex extends Searchengine
{ {
# Wir müssen herausfinden, ob es überhaupt noch weitere Ergebnisse von Yandex gibt: # Wir müssen herausfinden, ob es überhaupt noch weitere Ergebnisse von Yandex gibt:
try { try {
$content = simplexml_load_string($result); $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());
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error("Results from $this->name are not a valid json string");
return;
}
if (!$content) {
return; 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) { if (count($this->results) <= 0 || $pageLast >= $resultCount) {
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment