-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcrawler.php
More file actions
32 lines (30 loc) · 1004 Bytes
/
crawler.php
File metadata and controls
32 lines (30 loc) · 1004 Bytes
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
<?php
// 資料來自 http://data.taipei/opendata/datalist/datasetMeta?oid=9b7d78d2-0d73-4b42-9b29-c1640efed0eb
// 臺北市自動化3D近似建物模型
// 把這邊完整的 kmz, kml 爬到 kmzs/ 資料夾下
class Crawler
{
public function main($url)
{
$f = "kmzs/{$url}";
error_log($f);
if (!file_exists(dirname($f))) {
mkdir(dirname($f));
}
if (!file_exists($f)) {
file_put_contents($f, file_get_contents('http://adm3d.taipei.gov.tw/tcg/kml/Taipei3DBuilding/' . $url));
}
$c = file_get_contents($f);
preg_match_all('#<href>([^<]*)</href>#', $c, $matches);
foreach ($matches[1] as $new_url) {
if (strpos($new_url, 'http') === 0) {
continue;
}
if (strpos($new_url, 'kmz')) {
}
$this->main(dirname($url) . '/' . str_replace('\\', '/', $new_url));
}
}
}
$c = new Crawler;
$c->main('Taipei3DBuilding_nl.kml');