extrage-partidele-victorioase-din-lista-candidaților.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * File name:
  4. *
  5. *
  6. * (C) Copyright 2013 Friedrich-Ebert-Stiftung (http://fes.ro)
  7. * Author: Tiberiu C. Turbureanu (tct@ceata.org)
  8. *
  9. * This file is part of the project funded by FES
  10. *
  11. * This is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. $v = new DOMDocument();
  26. $v->formatOutput = true;
  27. $t = $v->appendChild($v->createElement("table"));
  28. $html = file_get_contents('../documente/candidații-pentru-bucurești-2012.html');
  29. $doc = new DOMDocument();
  30. $doc->loadHTML($html);
  31. $xpath = new DOMXpath($doc);
  32. $elements = $xpath->query("//tr[@class='ro2']");
  33. foreach ($elements as $e)
  34. {
  35. $party = $xpath->query("td/p", $e)->item(4)->nodeValue;
  36. if ($party == "62" || $party == "15" || $party == "57")
  37. {
  38. $t->appendChild($v->importNode($e->cloneNode(true), true));
  39. }
  40. }
  41. $v->saveHTMLFile('../documente/victorioșii-din-bucurești-2012.html');
  42. ?>