-
Notifications
You must be signed in to change notification settings - Fork 0
/
links.php
92 lines (78 loc) · 2.46 KB
/
links.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
<?php
require 'vendor/autoload.php';
use Sunra\PhpSimple\HtmlDomParser;
use GuzzleHttp\Client;
//$linkToCheck = 'http://www.emag.ro/carti/promotii/filter/gen-f1195,beletristica-v-314847/c';
function checkPagination($stringToCheck)
{
sleep(3);
// $client = new Client();
// $response = $client->get($stringToCheck);
// $body = $response->getBody();
//echo strlen($body);
$dom = HtmlDomParser::file_get_html($stringToCheck);
//var_dump($dom);
foreach($dom->find('div.listing-pagination') as $elements)
{
foreach ($elements->find('a') as $element) {
//return $element->href."\n";
$newlink = checkUrl($element->href);
if($newlink)
{
$links[$newlink] = true;
echo $newlink."\n";
}
}
}
}
// $test = 'http://www.emag.ro/carti/promotii/filter/gen-f1195,beletristica-v-314847/c';
$test = [
// 'http://www.emag.ro/atletism--alergare/nike/promotii/c' => '1',
// 'http://www.emag.ro/mers/converse/c?ref=menu_link_1308_9' => '1',
// 'http://www.emag.ro/televizoare/promotii/filter/smart-tv-f374,smart-tv-3d-v9406/c' => '1',
// 'http://www.emag.ro/aparate_foto_d-slr/promotii/c?ref=menu_link_1308_9' => '1',
// 'http://www.emag.ro/hrana/promotii/c' => '1',
// 'http://www.emag.ro/parfumuri/promotii/c' => '1',
// 'http://www.emag.ro/scutece-servetele/promotii/c' => '1',
// 'http://www.emag.ro/jucarii-jocuri-educative/promotii/c' => '1',
// 'http://www.emag.ro/petshop/l?ref=menu_banner_1308_11' => '1',
'http://www.emag.ro/telefoane-mobile/c' => '1',
'http://www.emag.ro/laptopuri-accesorii/l' => '1',
'http://www.emag.ro/laptopuri/c' => '1',
'http://www.emag.ro/carti/promotii/filter/gen-f1195,beletristica-v-314847/c' => '1',
];
foreach ($test as $key => $value)
{
echo checkPagination($key);
//var_dump(checkPagination($key));
}
// echo checkPagination($test);
function checkUrl($link)
{
if((substr($link, 0, 18) == "http://www.emag.ro"))
{
return $link;
}
else if((substr($link, 0, 18) !== "http://www.emag.ro"))
{
if(
(substr($link, 0, 10) === "javascript")
|| (substr($link, 0, 7) === "http://")
|| (strpos($link, 'microsoft') !== false)
|| (strpos($link, 'google') !== false)
|| (strpos($link, 'mozilla') !== false)
|| (strpos($link, 'https') !== false)
)
{
return false;
}
else if(substr($link, 0, 1) == "/")
{
return ("http://www.emag.ro".$link);
}
else
{
return ("http://www.emag.ro/".$link);
}
}
}