|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* https://github.com/elnurxf/tap-az-parser |
|
4
|
|
|
* TapTap - Tap.Az parser. |
|
5
|
|
|
* |
|
6
|
|
|
* (C) 2018 GNU General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
use GuzzleHttp\Client; |
|
9
|
|
|
use GuzzleHttp\Psr7\Request; |
|
10
|
|
|
use voku\helper\HtmlDomParser; |
|
11
|
|
|
|
|
12
|
|
|
class TapTap |
|
13
|
|
|
{ |
|
14
|
|
|
public $ads = []; |
|
15
|
|
|
public $ad = []; |
|
16
|
|
|
public $next_page = null; |
|
17
|
|
|
|
|
18
|
|
|
public function getAds($url) |
|
19
|
|
|
{ |
|
20
|
|
|
$client = new Client(); |
|
21
|
|
|
|
|
22
|
|
|
// get latest ad |
|
23
|
|
|
$request = new Request('GET', $url); |
|
24
|
|
|
$promise = $client->sendAsync($request)->then(function ($response) { |
|
25
|
|
|
$html = $response->getBody()->getContents(); |
|
26
|
|
|
|
|
27
|
|
|
$dom = HtmlDomParser::str_get_html($html); |
|
28
|
|
|
|
|
29
|
|
|
foreach ($dom->find('div.categories-products div.products div.products-i') as $product) { |
|
30
|
|
|
array_push($this->ads, $product->find('a.products-link', 0)->href); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// next page |
|
34
|
|
|
$this->next_page = $dom->find('div.pagination div.next a', 0)->href; |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
$promise->wait(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getAdDetails($url) |
|
41
|
|
|
{ |
|
42
|
|
|
$client = new Client(); |
|
43
|
|
|
|
|
44
|
|
|
// get ads |
|
45
|
|
|
$request = new Request('GET', $url); |
|
46
|
|
|
$promise = $client->sendAsync($request)->then(function ($response) { |
|
47
|
|
|
$html = $response->getBody()->getContents(); |
|
48
|
|
|
|
|
49
|
|
|
$dom = HtmlDomParser::str_get_html($html); |
|
50
|
|
|
|
|
51
|
|
|
// breadcrumbs |
|
52
|
|
|
foreach ($dom->find('div.breadcrumbs a') as $a) { |
|
53
|
|
|
$this->ad['categories'][] = [ |
|
54
|
|
|
'href' => $a->href, |
|
55
|
|
|
'name' => $a->plaintext, |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// title |
|
60
|
|
|
$this->ad['title'] = $dom->find('div.title-container h1')->plaintext; |
|
61
|
|
|
|
|
62
|
|
|
// price |
|
63
|
|
|
$this->ad['price'] = [ |
|
64
|
|
|
'value' => $dom->find('div.price-container div.price span.price-val', 0)->plaintext, |
|
65
|
|
|
'currency' => $dom->find('div.price-container div.price span.price-cur', 0)->plaintext, |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
|
|
// properties |
|
69
|
|
|
foreach ($dom->find('table.properties tr.property') as $property) { |
|
70
|
|
|
$this->ad['properties'][] = [ |
|
71
|
|
|
'name' => $property->find('td.property-name', 0)->innertext, |
|
72
|
|
|
'value' => $property->find('td.property-value', 0)->innertext, |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
// description |
|
77
|
|
|
$this->ad['description'] = $this->br2nl($dom->find('div.lot-text p', 0)->innertext); |
|
78
|
|
|
|
|
79
|
|
|
// author |
|
80
|
|
|
$this->ad['author'] = [ |
|
81
|
|
|
'name' => $dom->find('div.author div.name', 0)->innertext, |
|
82
|
|
|
'phone' => $dom->find('div.author a.phone', 0)->innertext, |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
// photos |
|
86
|
|
|
foreach ($dom->find('div.photos div.l-center div.short-view a') as $photo) { |
|
87
|
|
|
$this->ad['photos'][] = [ |
|
88
|
|
|
'thumb' => $photo->find('img', 0)->src, |
|
89
|
|
|
'large' => $photo->href, |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
}); |
|
93
|
|
|
|
|
94
|
|
|
$promise->wait(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
private function br2nl($buff = '') |
|
98
|
|
|
{ |
|
99
|
|
|
$buff = preg_replace('#<br[/\s]*>#si', "\n", $buff); |
|
100
|
|
|
$buff = trim($buff); |
|
101
|
|
|
|
|
102
|
|
|
return $buff; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|