Dom.php 653 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Spider\Lib;
  3. include(DEVER_APP_PATH . 'third/phpQuery.php');
  4. use Dever;
  5. use phpQuery;
  6. class Dom
  7. {
  8. private $query;
  9. public function __construct($url, $rule = '')
  10. {
  11. $html = $this->download($url);
  12. $dom = phpQuery::newDocumentHTML($html);
  13. if ($rule) {
  14. $dom = $this->find($dom, $rule);
  15. }
  16. $this->query = $dom;
  17. }
  18. private function download($url)
  19. {
  20. $download = new Download($url);
  21. return $download->get();
  22. }
  23. public function get()
  24. {
  25. return $this->query;
  26. }
  27. public function find($dom, $rule)
  28. {
  29. $rule = str_replace('$', '$dom->find', $rule);
  30. $cmd = '$dom = ' . $rule . ';';
  31. eval($cmd);
  32. return $dom;
  33. }
  34. }