парсер логов

Discussion in 'Болталка' started by mazaxaka, 10 Jul 2011.

  1. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    Нет, только в заданной директории. Прийдется по очереди парсить, просто новый путь указать до подпапки и новый файл для записи, так как он перезапишет данные, если в тот же файл парсить. Или вместо парметра mode "wb" напиши "ab", тогда при парсинге подпапки данные добавятся в result.txt
     
  2. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    ок с етим понятно..
    чтот не пашет
    запускаю
    хочу спарсить вк.
    в резулте
    в логе
    регулярка
    Code:
    ("#URL:.*http://login.vk.com.*\s(email: .*\pass: .*)
    где ошибка?
     
  3. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    PHP:
    <?php 
    set_time_limit
    (0);   
    function 
    file_parsing($dir)   
    {   
       global 
    $result
       
    $file_list '';   
       if (
    $dh opendir($dir))   
       { 
          while ((
    $file readdir($dh)) !== false)   
          {   
              if (
    $file !== '.' AND $file !== '..')   
              {   
                 
    $current_file "{$dir}\\{$file}";   
                 if (
    is_file($current_file))   
                 {   
                    
    $file file_get_contents($current_file); 
                    
    preg_match_all("#URL:.*vk.com.*\s(email:.*\spass:.*)#"$file$match);
                    if (
    count($match[1])>0)
                    {
                        
    $result .= implode(''$match[1])."\n";
                    }
                 } 
              }   
           }   
       }   
    }  
    $path "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки      
    file_parsing($path); 
    $fp fopen("result.txt""wb");//Спарсенные даные будут лежать в result.txt 
    fwrite($fp"vk.com:\n".trim($result)); 
    fclose($fp);
    ?>
    Теперь должно нормально парсить
     
  4. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    нечего не менял. на выходе в файле
    опять не нашло
     
  5. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    хм... что-то не могу сообразить почему не ищет. вопрос глупый, но ты уверен, что в этой папке есть лог с данными:
    URL: http://login.vk.com
    email: 375299461870
    pass: 10uыв
     
  6. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    да. он есть в 30-40% файлах

    там перед мылом и пасом еще пару пробелов есть. мб из-за етого?
     
  7. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    Если пробелы идут так:
    Code:
    URL: http://login.vk.com
      email: helga.krivko@tut.by
      pass: Красавица
    
    то конечно не найдет
     
  8. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    да так.. и че делать??
     
  9. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    подумать...
     
  10. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    та вот думаю в перле регурка норм парсит а в пхп не хочет
     
  11. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    PHP:
    <?php 
    set_time_limit
    (0);   
    function 
    file_parsing($dir)   
    {   
       global 
    $result
       
    $file_list '';   
       if (
    $dh opendir($dir))   
       { 
          while ((
    $file readdir($dh)) !== false)   
          {   
              if (
    $file !== '.' AND $file !== '..')   
              {   
                 
    $current_file "{$dir}\\{$file}";   
                 if (
    is_file($current_file))   
                 {   
                    
    $file file_get_contents($current_file); 
                    
    preg_match_all("#URL:.*vk.com.*\s+(email:.*\s+pass:.*)#"$file$match);
                    if (
    count($match[1])>0)
                    {
                        
    $result .= implode(''$match[1])."\n";
                    }
                 } 
              }   
           }   
       }   
    }  
    $path "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки      
    file_parsing($path);
    $result preg_replace("# #"""$result);
    $fp fopen("result.txt""wb");//Спарсенные даные будут лежать в result.txt 
    fwrite($fp"vk.com:\n".trim($result)); 
    fclose($fp);
    ?>
     
  12. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    ура наконецто))
    как тепреь избавится от лишнего?
    нужно убрать email: и pass:
    чтото кручу кручу. или не парсит или парсит так
     
  13. FaS

    FaS Elder - Старейшина

    Joined:
    3 Aug 2008
    Messages:
    64
    Likes Received:
    144
    Reputations:
    22
    блокнотом убрать
     
  14. FaS

    FaS Elder - Старейшина

    Joined:
    3 Aug 2008
    Messages:
    64
    Likes Received:
    144
    Reputations:
    22
    Поможет превратить логи вида:
    в такой:
    PHP:
    <?php
    $h 
    fopen("in.txt""r");
    $h1 fopen("out.txt""a+");

    while((
    $buf fgets($h)) !== false)
    {
         if(
    preg_match('/^.+?@+(.+?:.+?)$/'$buf$m))
         {
              
    fwrite($h1$m[1]."\r\n");
         }
    }

    fclose($h);
    fclose($h1);
    ?>
     
    #34 FaS, 11 Jul 2011
    Last edited: 11 Jul 2011
  15. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    ето тоже можно блокнотом))

    нафига блокнотом если удобней сделать все в скрипте
     
  16. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    Лень переделывать регэксп. Сделал так:
    PHP:
    <?php 
    set_time_limit
    (0);   
    function 
    file_parsing($dir)   
    {   
       global 
    $result
       
    $file_list '';   
       if (
    $dh opendir($dir))   
       { 
          while ((
    $file readdir($dh)) !== false)   
          {   
              if (
    $file !== '.' AND $file !== '..')   
              {   
                 
    $current_file "{$dir}\\{$file}";   
                 if (
    is_file($current_file))   
                 {   
                    
    $file file_get_contents($current_file); 
                    
    preg_match_all("#URL:.*vk.com.*\s+(email:.*\s+pass:.*\s)#"$file$match);
                    
    print_r($match);
                    if (
    count($match[1])>0)
                    {
                        
    $result .= implode(''$match[1])."\n";
                    }
                 } 
              }   
           }   
       }   
    }  
    $path "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки      
    file_parsing($path);
    $result preg_replace("# #"""$result);
    $arr explode("\n"$result);
    foreach (
    $arr as $line)
    {
        
    $res .= substr($linestrpos($line":")+1);
    }
    $fp fopen("result.txt""wb");//Спарсенные даные будут лежать в result.txt 
    fwrite($fp"vk.com:\n".trim($res)); 
    fclose($fp);
    ?>
     
  17. mazaxaka

    mazaxaka Elder - Старейшина

    Joined:
    15 Feb 2008
    Messages:
    268
    Likes Received:
    35
    Reputations:
    0
    а мож еще сделать чтобы сохронял
    не так
    а так
     
  18. Skofield

    Skofield Elder - Старейшина

    Joined:
    27 Aug 2008
    Messages:
    937
    Likes Received:
    355
    Reputations:
    58
    Ты бы сразу сказал как ты хочешь, а то так переделывать еще долго и нудно можно.
    PHP:
    <?php 
    set_time_limit
    (0);   
    function 
    file_parsing($dir)   
    {   
       global 
    $result
       
    $file_list '';   
       if (
    $dh opendir($dir))   
       { 
          while ((
    $file readdir($dh)) !== false)   
          {   
              if (
    $file !== '.' AND $file !== '..')   
              {   
                 
    $current_file "{$dir}\\{$file}";   
                 if (
    is_file($current_file))   
                 {   
                    
    $file file_get_contents($current_file); 
                    
    preg_match_all("#URL:.*vk.com.*\s+email:(.*)\s+pass:(.*)#"$file$match);
                    if (
    count($match[1])>0)
                    {
                        for (
    $i=0$i<count($match[1]); $i++)
                        {
                            
    $result .= trim($match[1][$i]).":".trim($match[2][$i])."\n";
                        }
                    }
                 } 
              }   
           }   
       }   
    }  
    $path "C:\WebServers\home\localhost\www\Новая папка";//Абсолютный путь до папки      
    file_parsing($path);
    $result preg_replace("# #"""$result);
    $fp fopen("result.txt""wb");//Спарсенные даные будут лежать в result.txt 
    fwrite($fp"vk.com:\n".trim($result)); 
    fclose($fp);
    ?>