-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_camping_location.php
42 lines (36 loc) · 1.2 KB
/
3_camping_location.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
<?php
# setup composer
include('simplehtmldom/simple_html_dom.php');
$file = file_get_contents('camping_location.csv');
$lines = explode("\n", $file);
$lineCount = count($lines);
foreach ($lines as $num => $line)
{
$str = "";
$items = str_getcsv($line);
// $str .= "|--- " .$items[0]. " - " . $items[1] . " - ". $items[3] ." ---|\n";
// $str .= "|--- " .$items[5]." ---|\n";
$html = file_get_html($items[5]);
foreach($html->find('div[class="box"]') as $key => $div)
{
if ($key == 2) {
$lat = "N/A";
$lon = "N/A";
foreach ($div->find('div[class="right-box"]') as $k => $b)
{
if ($k == 1)
{
$lat = trim(str_replace(" ", "", $b->plaintext));
}
elseif ($k == 3)
{
$lon = trim(str_replace(" ", "", $b->plaintext));
}
}
$str .= $items[0]. "," . $items[1] . "," . $lat . "," . $lon . "\n";
file_put_contents('./3_camping_locations/'.$items[4].'.csv', $str, FILE_APPEND);
}
}
// $str .= "\n\n";
echo $items[4]." - ".$num."/".$lineCount."\t\t\t\t\r";
}