| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 | <?phpnamespace Spider\Lib\Doc;include(DEVER_APP_PATH . 'third/phpQuery.php');use Dever;use phpQuery;class Dom{	public static function init($html)	{		if (strstr($html, 'gb2312')) {			$html = str_replace('gb2312', 'utf-8', $html);		}		return phpQuery::newDocumentHTML($html);	}	public static function find($dom, $rule)	{		list($rule, $attr) = self::each($rule);		$rule = str_replace(array('$', ').', '$dom->find.'), array('$dom->find', ')->', '$dom->'), $rule);		$cmd = '$dom = ' . $rule . ';';		eval($cmd);		return self::findAttr($dom, $attr);	}	public static function each($rule)	{		$attr = '';		if (strpos($rule, '.each().') !== false) {			$temp = explode('.each()', $rule);			$rule = $temp[0];			$attr = '$' . $temp[1];		}		return array($rule, $attr);	}	public static function findAttr($dom, $attr)	{		if (!$attr) {			return $dom;		}		$data = array();		foreach ($dom as $k => $v) {			$data[] = self::find(pq($v), $attr);		}		return json_encode($data, JSON_UNESCAPED_UNICODE);	}	public static function get($data)	{		return pq($data);	}	public static function rule($doc, $dom, $col, $rule, $key)	{		$result = Core::rule($doc, $dom, $col, $rule, $key);		return $result;	}}
 |