Skip to content

Commit 5a89a48

Browse files
committed
修复configs——之field 无效问题
1 parent dec4ac2 commit 5a89a48

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

core/phpspider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,7 @@ public function get_fields($confs, $html, $url, $page)
18311831
// 没有设置抽取规则的类型 或者 设置为 xpath
18321832
if (!isset($conf['selector_type']) || $conf['selector_type']=='xpath')
18331833
{
1834+
// 如果找不到,返回的是false
18341835
$values = $this->get_fields_xpath($html, $conf['selector'], $conf['name']);
18351836
}
18361837
elseif ($conf['selector_type']=='css')

core/selector.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ private static function _xpath_select($html, $selector, $remove = false)
116116
if ($elements === false)
117117
{
118118
self::$error = "the selector in the xpath(\"{$selector}\") syntax errors";
119-
return false;
119+
// 不应该返回false,因为isset(false)为true,更不能通过 !$values 去判断,因为!0为true,所以这里只能返回null
120+
//return false;
121+
return null;
120122
}
121123

122124
$result = array();
@@ -159,7 +161,7 @@ private static function _xpath_select($html, $selector, $remove = false)
159161
}
160162
if (empty($result))
161163
{
162-
return false;
164+
return null;
163165
}
164166
// 如果只有一个元素就直接返回string,否则返回数组
165167
return count($result) > 1 ? $result : $result[0];
@@ -210,14 +212,14 @@ private static function _regex_select($html, $selector, $remove = false)
210212
if(@preg_match_all($selector, $html, $out) === false)
211213
{
212214
self::$error = "the selector in the regex(\"{$selector}\") syntax errors";
213-
return false;
215+
return null;
214216
}
215217
$count = count($out);
216218
$result = array();
217219
// 一个都没有匹配到
218220
if ($count == 0)
219221
{
220-
return false;
222+
return null;
221223
}
222224
// 只匹配一个,就是只有一个 ()
223225
elseif ($count == 2)
@@ -242,7 +244,7 @@ private static function _regex_select($html, $selector, $remove = false)
242244
}
243245
if (empty($result))
244246
{
245-
return false;
247+
return null;
246248
}
247249

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

0 commit comments

Comments
 (0)