Mg_produkt2.php 1.89 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

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

class Mg_produkt2 extends Searchengine
9
{
10
11
12
13
14
15
    public $results = [];

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

17
18
19
20
21
    public function loadResults($result)
    {
        $result = preg_replace("/\r\n/si", "", $result);
        try {
            $content = simplexml_load_string($result);
22
23
24
            if (!$content) {
                return;
            }
25

26
            $results = $content->xpath('//response/result[@name="response"]/doc');
27

28
            foreach ($results as $result) {
29

30
31
32
33
34
                $result      = simplexml_load_string($result->saveXML());
                $title       = $result->xpath('/doc/arr[@name="artikelName"]')[0]->{"str"}->__toString();
                $link        = $result->xpath('/doc/arr[@name="artikelDeeplink"]')[0]->{"str"}->__toString();
                $anzeigeLink = parse_url($link);
                parse_str($anzeigeLink['query'], $query);
35
                $anzeigeLink = $query['url'];
36
37
38
39
40
41
42
43
44
                $descr       = $result->xpath('/doc/arr[@name="artikelBeschreibung"]')[0]->{"str"}->__toString();
                $image       = $result->xpath('/doc/arr[@name="artikelImageurl"]')[0]->{"str"}->__toString();
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
45
                    $this->displayName,$this->homepage,
46
                    $this->counter,
47
                    ['image' => $image]
48
49
50
                );
            }
        } catch (\Exception $e) {
51
52
            Log::error("A problem occurred parsing results from $this->name:");
            Log::error($e->getMessage());
53
54
55
            return;
        }
    }
56
}