diff --git a/core/phpspider.php b/core/phpspider.php index b253b97..bff6748 100755 --- a/core/phpspider.php +++ b/core/phpspider.php @@ -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') diff --git a/core/selector.php b/core/selector.php index 4d8d001..f17cff4 100644 --- a/core/selector.php +++ b/core/selector.php @@ -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(); @@ -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]; @@ -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) @@ -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];