protected function match($exp, $pattern, $value) {
switch ($exp) {
case '=':
return ($value===$pattern);
case '!=':
return ($value!==$pattern);
case '^=':
return preg_match("/^".preg_quote($pattern,'https://www.jb51.net/')."https://www.jb51.net/", $value);
case '$=':
return preg_match("https://www.jb51.net/".preg_quote($pattern,'https://www.jb51.net/')."$/", $value);
case '*=':
if ($pattern[0]=='https://www.jb51.net/')
return preg_match($pattern, $value);
return preg_match("https://www.jb51.net/".$pattern."/i", $value);
}
return false;
}
protected function parse_selector($selector_string) {
// pattern of CSS selectors, modified from mootools
$pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER);
$selectors = array();
$result = array();
//print_r($matches);
foreach ($matches as $m) {
$m[0] = trim($m[0]);
if ($m[0]==='' || $m[0]==='https://www.jb51.net/' || $m[0]==='//') continue;
// for borwser grnreated xpath
if ($m[1]==='tbody') continue;
list($tag, $key, $val, $exp, $no_key) = array($m[1], null, null, '=', false);
if(!empty($m[2])) {$key='id'; $val=$m[2];}
if(!empty($m[3])) {$key='class'; $val=$m[3];}
if(!empty($m[4])) {$key=$m[4];}
if(!empty($m[5])) {$exp=$m[5];}
if(!empty($m[6])) {$val=$m[6];}
// convert to lowercase
if ($this->dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);}
//elements that do NOT have the specified attribute
if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;}