22e4c6d0b5f986c6d9d053da75d3655aacaf608e.svn-base 795 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. include_once('../../simple_html_dom.php');
  3. function scraping_slashdot() {
  4. // create HTML DOM
  5. $html = file_get_html('http://slashdot.org/');
  6. // get article block
  7. foreach($html->find('div[id^=firehose-]') as $article) {
  8. // get title
  9. $item['title'] = trim($article->find('a.datitle', 0)->plaintext);
  10. // get body
  11. $item['body'] = trim($article->find('div.body', 0)->plaintext);
  12. $ret[] = $item;
  13. }
  14. // clean up memory
  15. $html->clear();
  16. unset($html);
  17. return $ret;
  18. }
  19. // -----------------------------------------------------------------------------
  20. // test it!
  21. $ret = scraping_slashdot();
  22. foreach($ret as $v) {
  23. echo $v['title'].'<br>';
  24. echo '<ul>';
  25. echo '<li>'.$v['body'].'</li>';
  26. echo '</ul>';
  27. }
  28. ?>