Mnogosearch.php 1.5 KB
Newer Older
1
2
3
<?php

namespace app\Models\parserSkripte;
4

5
6
7
use App\Models\Searchengine;
use Symfony\Component\DomCrawler\Crawler;

8
class Mnogosearch extends Searchengine
9
{
10
11
    public $results = [];

Dominik Hebeler's avatar
Dominik Hebeler committed
12
    public function __construct($name, \stdClass $engine, \App\MetaGer $metager)
13
    {
Dominik Hebeler's avatar
Dominik Hebeler committed
14
        parent::__construct($name, $engine, $metager);
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    }

    public function loadResults($result)
    {
        $counter = 0;
        $crawler = new Crawler($result);
        $crawler->filter('table[width=600]')
            ->reduce(function (Crawler $node, $i) {
                if (strpos($node->text(), "Result pages:") !== false) {
                    return false;
                }
            })
            ->each(function (Crawler $node, $i) {
                $title = $node->filter('table > tr > td ')->eq(1)->filter('td > div')->text();
                $title = preg_replace("/\s+/si", " ", $title);

Dominik Hebeler's avatar
Dominik Hebeler committed
31
                $link = $node->filter('table > tr > td ')->eq(1)->filter('td > div > a')->attr('href');
32
                $anzeigeLink = $link;
Dominik Hebeler's avatar
Dominik Hebeler committed
33
                $descr = $node->filter('table > tr > td ')->eq(1)->filter('td > div')->eq(1)->text();
34
35
36
37
38
39
40
41
                $this->counter++;

                $this->results[] = new \App\Models\Result(
                    $this->engine,
                    $title,
                    $link,
                    $anzeigeLink,
                    $descr,
Dominik Hebeler's avatar
Dominik Hebeler committed
42
                    $this->engine->{"display-name"}, $this->engine->homepage,
43
44
45
46
47
48
                    $this->counter
                );
            });

    }
}