Skip to content

Commit

Permalink
修复configs——之field 无效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kaka committed Jul 16, 2018
1 parent dec4ac2 commit 5a89a48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/phpspider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,7 @@ public function get_fields($confs, $html, $url, $page)
// 没有设置抽取规则的类型 或者 设置为 xpath
if (!isset($conf['selector_type']) || $conf['selector_type']=='xpath')
{
// 如果找不到,返回的是false
$values = $this->get_fields_xpath($html, $conf['selector'], $conf['name']);
}
elseif ($conf['selector_type']=='css')
Expand Down
12 changes: 7 additions & 5 deletions core/selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private static function _xpath_select($html, $selector, $remove = false)
if ($elements === false)
{
self::$error = "the selector in the xpath(\"{$selector}\") syntax errors";
return false;
// 不应该返回false,因为isset(false)为true,更不能通过 !$values 去判断,因为!0为true,所以这里只能返回null
//return false;
return null;
}

$result = array();
Expand Down Expand Up @@ -159,7 +161,7 @@ private static function _xpath_select($html, $selector, $remove = false)
}
if (empty($result))
{
return false;
return null;
}
// 如果只有一个元素就直接返回string,否则返回数组
return count($result) > 1 ? $result : $result[0];
Expand Down Expand Up @@ -210,14 +212,14 @@ private static function _regex_select($html, $selector, $remove = false)
if(@preg_match_all($selector, $html, $out) === false)
{
self::$error = "the selector in the regex(\"{$selector}\") syntax errors";
return false;
return null;
}
$count = count($out);
$result = array();
// 一个都没有匹配到
if ($count == 0)
{
return false;
return null;
}
// 只匹配一个,就是只有一个 ()
elseif ($count == 2)
Expand All @@ -242,7 +244,7 @@ private static function _regex_select($html, $selector, $remove = false)
}
if (empty($result))
{
return false;
return null;
}

return count($result) > 1 ? $result : $result[0];
Expand Down

0 comments on commit 5a89a48

Please sign in to comment.