Advertisement
AMONRA75

PHP - SCRAPE AND WRITE CSV

Jul 11th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2.  
  3. //reporto errori
  4. error_reporting(E_ALL);
  5. ini_set("display_errors","On");
  6. set_time_limit(0);
  7. ini_set("memory_limit", -1);
  8.  
  9. //cancella file
  10. if (file_exists("lista.csv")) unlink("lista.csv");
  11.  
  12. //unlink("prova.csv");
  13.  
  14.  
  15.  
  16. $marks = [
  17.  
  18. "http://www.blackcave.it/lista/scripts.php" => ["name" => "#blackcave", "server" => "irc.tin.it"],
  19. "http://import.gigeweb.de/lista/scripts.php" => ["name" => "#immense", "server" => "irc.tin.it"],
  20. "http://r3volution.altervista.org/scripts.php" => ["name" => "#revolution", "server" => "irc.tin.it"],
  21. "http://www.serie-tv.cartaplayfan.org/scripts.php" => ["name" => "#serie-tv", "server" => "irc.irc-files.org"],
  22. "http://www.irc-files.cartaplayfan.org/listafilm/scripts.php" => ["name" => "#films", "server" => "irc.irc-files.org"],
  23. "http://www.silvestro.irc-files.org/scripts.php" => ["name" => "#silvestro", "server" => "irc.irc-files.org"],
  24. "http://www.magic.irc-files.org/scripts.php" => ["name" => "#magic", "server" => "irc.irc-files.org"],
  25. "http://www.hd.cartaplayfan.org/scripts.php" => ["name" => "#irc-HD", "server" => "irc.irc-files.org"],
  26. "http://www.fantasyland.irc-files.org/scripts.php" => ["name" => "#fantasyland", "server" => "irc.irc-files.org"],
  27. "http://lista.oceanirc.net/lwo/scripts.php" => ["name" => "#oce@n", "server" => "irc.oceanirc.net"],
  28. "http://www.fantasyland.irc-files.org/scripts.php" => ["name" => "#fantasyland", "server" => "irc.irc-files.org"],
  29.  
  30. ];
  31.  
  32.  
  33.  
  34.  
  35.  
  36. foreach ($marks as $name=>$scores){
  37. //echo $name ." - ". $scores["server"] . " - ". $scores["name"] . ".\r";
  38.  
  39.  
  40. $chanserv = $scores["name"].";".$scores["server"];
  41.  
  42.  
  43. $input = @file_get_contents($name) or die("Could not access file: $name");
  44.  
  45. //rimuovo prima lettera in questo caso ";"
  46. $str1 = ltrim($input);
  47. //rimpiazzo gli spazi con ;
  48. $str = preg_replace('/\s+/', ';', $str1);
  49.  
  50.  
  51. //porto a capo quando trovo ;#
  52. $all = str_replace(";#", "\n\r", $str);
  53. //($all = str_replace(";#", $chanserv, $str);
  54. //$str.= $chanserv;
  55.  
  56.  
  57. //rimuovo prima lettera
  58. $all2 = substr($str,1);
  59. //rimuovo ultima lettera
  60. $all3 = substr_replace($all2, "", -1);
  61. $print = str_replace(";#", ";".$chanserv."<br>", $str);
  62.  
  63.  
  64. echo $print;
  65. echo memory_get_usage();
  66.  
  67.  
  68. /*
  69. $data = $all3.PHP_EOL;
  70. //$fp = fopen($scores["name"].".csv", 'a'); singoli files
  71. $fp = fopen(lista.".csv", 'a');
  72. //fwrite($fp, $data);
  73. fwrite($fp, $print);
  74. */
  75.  
  76.  
  77.  
  78. $data = $all3.PHP_EOL;
  79. $handle = fopen("lista.csv", 'a');
  80.  
  81. fwrite($handle, $data);
  82. fclose($handle);
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement