This commit is contained in:
Jaeger 2017-09-21 01:44:03 +08:00
parent 8bd07f5fbb
commit 02fe5a7f9e
2 changed files with 10 additions and 9 deletions

View File

@ -4,9 +4,9 @@
"keywords":["QueryList","phpQuery","spider"], "keywords":["QueryList","phpQuery","spider"],
"homepage": "http://querylist.cc", "homepage": "http://querylist.cc",
"require": { "require": {
"PHP":">=5.6.0", "PHP":">=7.0",
"jaeger/phpquery-single": "^0.9", "jaeger/phpquery-single": "^0.9",
"illuminate/support": "^5.5" "tightenco/collect": "^5.5"
}, },
"suggest":{ "suggest":{
"monolog/monolog":"Log support" "monolog/monolog":"Log support"
@ -22,5 +22,8 @@
"psr-4":{ "psr-4":{
"QL\\":"src" "QL\\":"src"
} }
},
"require-dev": {
"symfony/var-dumper": "^3.3"
} }
} }

View File

@ -21,6 +21,7 @@ class QueryList
protected $document; protected $document;
protected $rules; protected $rules;
protected $range = null; protected $range = null;
protected $encoder;
/** /**
* QueryList constructor. * QueryList constructor.
@ -88,10 +89,9 @@ class QueryList
$robj = pq($document)->find($this->range); $robj = pq($document)->find($this->range);
$i = 0; $i = 0;
foreach ($robj as $item) { foreach ($robj as $item) {
while (list($key, $reg_value) = each($this->rules)) { foreach ($this->rules as $key => $reg_value){
$tags = isset($reg_value[2])?$reg_value[2]:''; $tags = $reg_value[2] ?? '';
$iobj = pq($item)->find($reg_value[0]); $iobj = pq($item)->find($reg_value[0]);
switch ($reg_value[1]) { switch ($reg_value[1]) {
case 'text': case 'text':
$data[$i][$key] = $this->allowTags(pq($iobj)->html(),$tags); $data[$i][$key] = $this->allowTags(pq($iobj)->html(),$tags);
@ -108,13 +108,11 @@ class QueryList
$data[$i][$key] = call_user_func($reg_value[3],$data[$i][$key],$key); $data[$i][$key] = call_user_func($reg_value[3],$data[$i][$key],$key);
} }
} }
//重置数组指针
reset($this->rules);
$i++; $i++;
} }
} else { } else {
while (list($key, $reg_value) = each($this->rules)) { foreach ($this->rules as $key => $reg_value){
$tags = isset($reg_value[2])?$reg_value[2]:''; $tags = $reg_value[2] ?? '';
$lobj = pq($document)->find($reg_value[0]); $lobj = pq($document)->find($reg_value[0]);
$i = 0; $i = 0;
foreach ($lobj as $item) { foreach ($lobj as $item) {