Allesklar.php 1.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

namespace App\Models\parserSkripte;

use App\Models\Searchengine;
use Symfony\Component\DomCrawler\Crawler;

class Allesklar extends Searchengine
{
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    protected $tds = "";
    public function __construct(\SimpleXMLElement $engine, \App\MetaGer $metager)
    {
        parent::__construct($engine, $metager);
    }

    public function loadResults($result)
    {
        $crawler = new Crawler(utf8_decode($result));
        $crawler = $crawler
            ->filter('table[width=585]')
            ->reduce(function (Crawler $node, $i) {
                if ($i < 5) {
                    return false;
                }
            });

        $this->counter = 0;
        $crawler->filter('table')->each(function (Crawler $node, $i) {
            try {
                $this->string = "";
                $titleTag     = $node->filter('tr > td > a')->first();
                $title        = trim($titleTag->filter('a')->text());
                $link         = $titleTag->filter('a')->attr('href');
                if ($i === 0) {
                    $descr = trim($node->filter('tr > td.bodytext')->eq(3)->text());
                } else {
                    $descr = trim($node->filter('tr > td.bodytext')->eq(2)->text());
                }
                $this->counter++;
                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $link,
                    $descr,
                    $this->gefVon,
                    $this->counter
                );
Karl's avatar
Karl committed
49
50
51
            } catch (\Exception $e) {
                Log::error("A problem occurred parsing results from $this->name");
                return;
52
53
54
55
56
            }
        });
    }

}