thieumao

simplehtmldom demo - Phân tích HTML - PHP Simple HTML DOM Pa

Nov 24th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. // example of how to use advanced selector features
  3. include('../simplehtmldom/simple_html_dom.php');
  4.  
  5. // -----------------------------------------------------------------------------
  6.  
  7. $phancach = "----------------------------------------------------------------------------- <br/>";
  8.  
  9. // Retrieve the DOM from a given URL
  10. $html = file_get_html('http://libamboo.so/forum/');
  11.  
  12. // Find all "A" tags and print their HREFs
  13. foreach($html->find('a') as $e)
  14.     echo $e->href . '<br>';
  15. echo $phancach;
  16.  
  17. // Retrieve all images and print their SRCs
  18. foreach($html->find('img') as $e)
  19.     echo $e->src . '<br>';
  20. echo $phancach;
  21.  
  22. // Find all images, print their text with the "<>" included
  23. foreach($html->find('img') as $e)
  24.     echo $e->outertext . '<br>';
  25. echo $phancach;
  26.  
  27. // Find the DIV tag with an id of "myId"
  28. foreach($html->find('div#myId') as $e)
  29.     echo $e->innertext . '<br>';
  30. echo $phancach;
  31.  
  32. // Find all SPAN tags that have a class of "myClass"
  33. foreach($html->find('span.myClass') as $e)
  34.     echo $e->outertext . '<br>';
  35. echo $phancach;
  36.  
  37. // Find all TD tags with "align=center"
  38. foreach($html->find('td[align=center]') as $e)
  39.     echo $e->innertext . '<br>';
  40. echo $phancach;
  41.    
  42. // Extract all text from a given cell
  43. echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>';
  44.  
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment