"10.90.1.201", "database1" => "opendata", "database2" => "niimko", "user" => "niimko_user", "password" => "MOhA17FeboXE" ]; $dbOpendata = new Database( "mysql:host={$dbconfig['host']};dbname={$dbconfig['database1']}", $dbconfig['user'], $dbconfig['password'] ); $dbNiimko = new Database( "mysql:host={$dbconfig['host']};dbname={$dbconfig['database2']}", $dbconfig['user'], $dbconfig['password'] ); $builder = new GenericBuilder(); // select kod as org_id, site from niimko.s_vuzes // where ootype = 'vuz' and deleted = 'n' and fake = 'n' $params = ['vuz', 'n', 'n']; $query = $builder->select() ->setTable('s_vuzes') ->setColumns(['org_id' => 'kod', 'site']) ->where('AND') ->equals('ootype', 'vuz') ->equals('deleted', 'n') ->equals('fake', 'n') ->end(); $sql = $builder->write($query); $sites = $dbNiimko->executeQuery($sql, $params); // select id, kod from niimko.s_specs where oopkodes = 'gos3p' $params = ['gos3p']; $query = $builder->select() ->setTable('s_specs') ->setColumns(['id', 'kod']) ->where() ->equals('oopkodes','gos3p') ->end(); $sql = $builder->write($query); $specializations = $dbNiimko->executeQuery($sql, $params); // print_r($sites); // print_r($specializations); // $sites = [ ['site' => "http://marsu.ru"], ['site' => "http://voenmeh.ru"], ['site' => "http://angtu.ru"] ]; $i = 0; $succes = 0; foreach ($sites as $site) { try { $client = new Client([ RequestOptions::ALLOW_REDIRECTS => [ 'max' => 10, // allow at most 10 redirects. 'strict' => true, // use "strict" RFC compliant redirects. 'referer' => true, // add a Referer header 'track_redirects' => true, ], ]); $route = "{$site['site']}/sveden/education/"; $route = str_replace("http","https", $route); $route = str_replace("www.","", $route); print(++$i.". Current url: $route\n"); $response = $client->get($route); print("StatusCode: ".$response->getStatusCode() . "\n"); $html = $response->getBody()->getContents(); $parser = new ContingentParser($html, '//tr[@itemprop="eduChislen"]//'); $contingent = $parser->getDataTable(); // Добавляем поле spec_id по spec_code foreach ($contingent as $key => $con) { $needle = $con['spec_code']; foreach ($specializations as $spec) { if ($needle == $spec['kod']) { $con['spec_id'] = $spec['id']; } } $contingent[$key]['spec_id'] = $con['spec_id']; } // Добавляем поле org_id foreach ($contingent as $key => $spec) { $contingent[$key]['org_id'] = $site['org_id']; } print_r($contingent); if ($response->getStatusCode() == 200 && !empty($contingent)){ print("Succes: ".++$succes."\n"); } } catch (ClientException $e) { $response = $e->getCode(); } catch (RequestException $e) { $response = $e->getCode(); } catch (ConnectException $e) { $response = $e->getCode(); } catch (ServerException $e) { $response = $e->getCode(); } } // Чтобы не дублировались в базе // $dbOpendata->insert('sveden_education_contingent', $data); // $dbOpendata->update('sveden_education_contingent', $specializations); // $data = $dbOpendata->select('sveden_education_contingent');