-
Notifications
You must be signed in to change notification settings - Fork 1
/
moko.php
35 lines (31 loc) · 951 Bytes
/
moko.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
<?php
require 'lib.php';
function fetch_page($page_url)
{
$html = file_get_contents($page_url);
// echo $html;
if (!preg_match_all('/<img src2="([^"]+?)"/i', $html, $matches)) {
throw new Exception("no img", 1);
}
foreach ($matches[1] as $image_url) {
$file_name = substr($image_url, strrpos($image_url, '/')+1);
$file_name = __DIR__.'/images/'.$file_name;
if (is_file($file_name)) {
echo "skip $file_name\n";
continue;
}
echo "save $file_name \n";
image_save($file_name, $image_url);
}
return count($matches[1]);
}
$root = 'http://www.moko.cc/';
$html = file_get_contents($root);
if (!preg_match_all('%<a href="/(post/\d+.html)"%i', $html, $matches)) {
throw new Exception("no link to page", 1);
}
foreach ($matches[1] as $link) {
$link = $root.$link;
echo "fetch $link\n";
fetch_page($link, '/<img src2="([^"]+?)"/i');
}