Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2.  
  3. $html = file_get_contents('myfileurl'); //get the html returned from the following url
  4.  
  5. $pokemon_doc = new DOMDocument();
  6.  
  7. libxml_use_internal_errors(TRUE); //disable libxml errors
  8.  
  9. if (!empty($html)) { //if any html is actually returned
  10. $pokemon_doc->loadHTML($html);
  11. libxml_clear_errors(); //remove errors for yucky html
  12.  
  13. $pokemon_xpath = new DOMXPath($pokemon_doc);
  14.  
  15. //get all the h2's with an id
  16. $pokemon_row = $pokemon_xpath->query("//li[@class='content']");
  17.  
  18. if ($pokemon_row->length > 0) {
  19. foreach ($pokemon_row as $row) {
  20. $title = $row->getElementsByTagName('h3');
  21. foreach ($title as $a) {
  22. echo "Title: ";
  23. echo strip_tags($a->nodeValue). '<br>';
  24. }
  25. $links = $row->getElementsByTagName('a');
  26. foreach ($links as $l) {
  27. echo "Link: ";
  28. echo strip_tags($l->nodeValue). '<br>';
  29. }
  30. $desc = $row->getElementsByTagName('span');
  31.  
  32. //I tried that but didnt work..... iwant to get the span with class desc
  33. //$desc = $row->query("//span[@class='desc']");
  34.  
  35. foreach ($desc as $d) {
  36. echo "DESC: ";
  37. echo strip_tags($d->nodeValue) . '<br><br>';
  38. }
  39. // echo $row->nodeValue . "<br/>";
  40. }
  41. }
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement