-
Notifications
You must be signed in to change notification settings - Fork 0
/
goutte.php
31 lines (25 loc) · 899 Bytes
/
goutte.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
<?php
require 'vendor/autoload.php';
use Goutte\Client;
simpleMySQL\Model::setParams('localhost','root','b1otope','lbc');
$client = new Client();
$fp = fopen('department.csv','r+');
$model = new \OP\LBC\Model\NearDepartment();
while($row = fgetcsv($fp)){
$departmentName = $row[4];
$number = $row[1];
$url = $departmentName.'-'.$number.'.php';
$crawler = $client->request('GET', 'http://www.france-departements.fr/'.$url);
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 20);
$model->add(
array('idDepartment'=>$number,'idNearDepartment'=>$number)
);
$crawler->filter('.fiche-middle-right > ul > li')->each(function($node) use($model,$number){
$dep = $node->text();
$tab = explode('-',$dep);
$dept = trim($tab[count($tab)-1]);
$model->add(
array('idDepartment'=>$number,'idNearDepartment'=>$dept)
);
});
}