Ecoshopper.php 1.9 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
use App\Models\Searchengine;
6
use Log;
7

8
class Ecoshopper extends Searchengine
9
{
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    public $results = [];

    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
    }

    public function loadResults($result)
    {
        try {
            $content = simplexml_load_string($result);
        } catch (\Exception $e) {
            Log::error("Ergebnisse von Ecoshopper konnten nicht eingelesen werden");
            return;
        }
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
        if (!$content) {
            return;
        }
        $results = $content->xpath('//response/result[@name="response"]/doc');
        foreach ($results as $result) {
            $result      = simplexml_load_string($result->saveXML());
            $title       = $result->xpath('//doc/str[@name="artikelName"]')[0]->__toString();
            $link        = $result->xpath('//doc/str[@name="artikelDeeplink"]')[0]->__toString();
            $anzeigeLink = parse_url($link);
            if (isset($anzeigeLink['query'])) {
                parse_str($anzeigeLink['query'], $query);
                if (isset($query['diurl'])) {
                    $anzeigeLink = $query['diurl'];
                } else {
                    $anzeigeLink = $link;
                }
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
            } else {
                $anzeigeLink = $link;
            }
            $descr = $result->xpath('//doc/str[@name="artikelBeschreibung"]')[0]->__toString();
            $image = $result->xpath('//doc/str[@name="artikelImageurl"]')[0]->__toString();
            $this->counter++;
            $this->results[] = new \App\Models\Result(
                $this->engine,
                $title,
                $link,
                $anzeigeLink,
                $descr,
                $this->gefVon,
                $this->counter,
                false,
                $image
            );
        }
    }
62
}