-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTapTap.php
104 lines (84 loc) · 3.09 KB
/
TapTap.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* https://github.com/elnurxf/tap-az-parser
* TapTap - Tap.Az parser.
*
* (C) 2018 GNU General Public License
*/
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use voku\helper\HtmlDomParser;
class TapTap
{
public $ads = [];
public $ad = [];
public $next_page = null;
public function getAds($url)
{
$client = new Client();
// get latest ad
$request = new Request('GET', $url);
$promise = $client->sendAsync($request)->then(function ($response) {
$html = $response->getBody()->getContents();
$dom = HtmlDomParser::str_get_html($html);
foreach ($dom->find('div.categories-products div.products div.products-i') as $product) {
array_push($this->ads, $product->find('a.products-link', 0)->href);
}
// next page
$this->next_page = $dom->find('div.pagination div.next a', 0)->href;
});
$promise->wait();
}
public function getAdDetails($url)
{
$client = new Client();
// get ads
$request = new Request('GET', $url);
$promise = $client->sendAsync($request)->then(function ($response) {
$html = $response->getBody()->getContents();
$dom = HtmlDomParser::str_get_html($html);
// breadcrumbs
foreach ($dom->find('div.breadcrumbs a') as $a) {
$this->ad['categories'][] = [
'href' => $a->href,
'name' => $a->plaintext,
];
}
// title
$this->ad['title'] = $dom->find('div.title-container h1')->plaintext;
// price
$this->ad['price'] = [
'value' => $dom->find('div.price-container div.price span.price-val', 0)->plaintext,
'currency' => $dom->find('div.price-container div.price span.price-cur', 0)->plaintext,
];
// properties
foreach ($dom->find('table.properties tr.property') as $property) {
$this->ad['properties'][] = [
'name' => $property->find('td.property-name', 0)->innertext,
'value' => $property->find('td.property-value', 0)->innertext,
];
}
// description
$this->ad['description'] = $this->br2nl($dom->find('div.lot-text p', 0)->innertext);
// author
$this->ad['author'] = [
'name' => $dom->find('div.author div.name', 0)->innertext,
'phone' => $dom->find('div.author a.phone', 0)->innertext,
];
// photos
foreach ($dom->find('div.photos div.l-center div.short-view a') as $photo) {
$this->ad['photos'][] = [
'thumb' => $photo->find('img', 0)->src,
'large' => $photo->href,
];
}
});
$promise->wait();
}
private function br2nl($buff = '')
{
$buff = preg_replace('#<br[/\s]*>#si', "\n", $buff);
$buff = trim($buff);
return $buff;
}
}