-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
59 lines (41 loc) · 1.04 KB
/
example.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
<?php
/*
Autor: Maciej Włodarczak (https://eskim.pl)
Wersja: 1.0
Na podstawie artykułu: https://eskim.pl/pobieranie-strony-offline-w-php/
*/
include_once 'spider.php';
$dir = 'website/';
$url = 'https://example.com';
$linksfn = 'links.data';
$spider = new Spider($url, 'index.html');
if (file_exists($linksfn) ) {
$links = json_decode (file_get_contents ($linksfn), true);
}
else {
$links[ 'index.html' ] = [
'link' => $url,
'discover' => time(),
'downloaded' => false
];
}
if (!file_exists($dir)) mkdir($dir);
$counter = 0;
$count = count($links);
while ($counter < $count) {
$key = key($links);
if (!$links[$key]['downloaded']) {
echo "Progress: $counter / $count \n";
$page = $spider->getWebsite ( $links[$key]['link'] );
$local = $spider->convertToLocal ( $page );
file_put_contents( $dir.$key, $local );
$links[$key]['downloaded'] = true;
$spider->getLinks($page, $links);
$count = count($links);
file_put_contents( $linksfn, json_encode($links) );
$spider->wait();
}
next($links);
$counter++;
}
?>