1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace Spider\Lib;
- include(DEVER_APP_PATH . 'third/phpQuery.php');
- use Dever;
- use phpQuery;
- class Dom
- {
- private $query;
- public function __construct($url, $rule = '')
- {
- $html = $this->download($url);
- $dom = phpQuery::newDocumentHTML($html);
- if ($rule) {
- $dom = $this->find($dom, $rule);
- }
-
- $this->query = $dom;
- }
- private function download($url)
- {
- $download = new Download($url);
- return $download->get();
- }
- public function get()
- {
- return $this->query;
- }
- public function find($dom, $rule)
- {
- $rule = str_replace('$', '$dom->find', $rule);
- $cmd = '$dom = ' . $rule . ';';
- eval($cmd);
- return $dom;
- }
- }
|