<?php
$input="links-sec-ru.txt";
$output="get-sec-ru.txt";
$ids = array();
$fin = fopen($input, 'r');
$fout = fopen($output, 'w+');
while (($url = fgets($fin)) !== false) {
if (!preg_match('/http:\/\/catalog\.sec\.ru\/firms\.cfm\?.{0,}fid=(\d+)/', $url, $matches)) {
continue;
}
if (array_key_exists($matches[1], $ids)) {
continue;
}
$url = 'http://catalog.sec.ru/firms.cfm?fid=' . $matches[1];
$ids[$matches[1]] = true;
//Получаем файл
$body=(file_get_contents($url));
$pos = strpos($body, '<p style="padding-left: 20; padding-bottom: 5; padding-top:13;">');
$body= substr($body, $pos);
$pos = strpos($body, '</table>');
$body = substr($body, 0, $pos);
//Имя
$pos = strpos($body,'</font><font style="font-size: 18; color: #888888">');
if($pos !== false) {
$name = substr($body, 0, $pos);
}
//Форма
$pos = strpos($body, 'Форма собственности:');
if($pos !== false) {
$forma= substr($body, $pos);
$pos = strpos($forma,'</p>');
$forma = explode(":</font>",substr($forma, 0, $pos));
}
//Полный адрес
$pos = strpos($body, 'Полный адрес:');
if($pos !== false) {
$adr= substr($body, $pos);
$pos = strpos($adr,'</p>');
$adr = explode(":</font>",substr($adr, 0, $pos));
}
//Телефон
$pos = strpos($body, 'Тел:');
if($pos !== false) {
$tel= substr($body, $pos);
$pos = strpos($tel,'</p>');
$tel = explode("nobr>",substr($tel, 0, $pos));
$tel = explode(":",$tel[0]);
}
//Сайт
$pos = strpos($body, 'Web-сервер:');
if($pos !== false) {
$site= substr($body, $pos);
$pos = strpos($site,'</a>');
$site = explode(":</font>",substr($site, 0, $pos));
}
//мыло
$pos = strpos($body, 'E-mail(s):');
if($pos !== false) {
$mail= substr($body, $pos);
$pos = strpos($mail,'</a>');
$mail = explode(":</font>",substr($mail, 0, $pos));
}
$data = ""
.trim(strip_tags($name)).";"
.trim(strip_tags($forma[1])).";"
.trim(strip_tags($adr[1])).";"
.trim(strip_tags($tel[1])).";"
.trim(strip_tags($site[1])).";"
.trim(strip_tags($mail[1]))."#";
fwrite($fout, $data);
}
fclose($fout);
fclose($fin);