-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantwerpen.php
81 lines (61 loc) · 1.76 KB
/
antwerpen.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
<?php
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
//dependencies
require(dirname(__FILE__) . "/simple_html_dom.php");
class ChargePoint
{
public $name = "";
public $city = "";
public $district = "";
public $url = "";
public $zip = "";
public $street = "";
function __construct($name, $city, $district, $url) {
$this->name = $name;
$this->url = $url;
$this->city = $city;
$this->district = $district;
}
}
class Crawler
{
public $url = '';
public $response = null;
public $result = null;
public function __construct($url)
{
$this->url = $url;
}
public function getData($url)
{
$this->response = file_get_html( $this->url . $url );
$i=0;
foreach($this->response->find('tr') as $element)
{
if(!is_null($element->find('td span',0))
&& trim(strtolower($element->find('td span',0)->plaintext)) != "naam"
&& trim($element->find('td span',3)->plaintext) == "auto"
) {
$p = new ChargePoint(
trim( strtolower ( $element->find('td span',0)->plaintext)),
trim( strtolower ( $element->find('td span',1)->plaintext)),
trim( strtolower ( $element->find('td span',2)->plaintext)),
$element->find('td span a',0)->href
);
$this->extend($p);
$this->result[] = $p;
}
}
}
private function extend(&$obj){
$details = file_get_html($this->url . urldecode($obj->url) );
preg_match('/Adres: (.*) Postcode en Gemeente: (\d*)/', preg_replace('/\s+/', ' ',$details->find('.mainContent_column .mainContent_column_inlay',0)->plaintext), $matches);
$obj->street = $matches[1];
$obj->zip = $matches[2];
}
}
header('Content-Type: application/json');
$c = new Crawler("http://www.oplaadpunten.org/");
$c->getData("Oplaadpunten-Antwerpen.php");
print json_encode($c->result)
?>