Allesklar.php 1.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
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
49
50
51
52
53
54
55
56
57
58
59
60
<?php

namespace App\Models\parserSkripte;

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

class Allesklar extends Searchengine
{
	protected $tds = "";
	function __construct (\SimpleXMLElement $engine, $mh, \App\MetaGer $metager)
	{
		parent::__construct($engine, $mh, $metager);
	}

	public function loadResults (String $result)
	{
		$crawler = new Crawler($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(
					$title,
					$link,
					$link,
					$descr,
					$this->gefVon,
					$this->counter
					);
			} catch (\InvalidArgumentException $e)
			{

			}
				
		});	
	}

}