XPATH - 规范化-space 具有超过 1 个文本用于计数目的

XPATH - normalize-space with more than 1 text for counting purposes

大家好,我是菜鸟,

https://decisoesesolucoes.com/agencias/albergaria/consultores

在上面的url中,我想统计'consultor imobiliario'和'Consultora Imobiliaria'的个数,这两个文本都有space,为什么我要使用normalize -space.

The text i want to get

示例:

"//*[text()[normalize-space() = 'consultor imobiliario']]" - 这有效

但是如果我也想计算,'Consultora Imobiliaria' 不起作用:

"//*[text()[normalize-space() = 'consultor imobiliario' and 'Consultora Imobiliária']]"  

(if I user OR instead AND the counting = bad count)

我的完整代码是:

$current_page = 1;
$max_page = 999999999999;
$countTotalConsultores=0;

while($max_page >= $current_page){

$url = "https://decisoesesolucoes.com/agencias/albergaria/consultores?page=";
$url .= $current_page;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$res = curl_exec($ch);

curl_close($ch);

$dom = new DomDocument();
@ $dom->loadHTML($res);

$xpath = new DOMXpath($dom);
$body = $xpath->query("//*[text()[normalize-space() = 'consultor imobiliario' and 'Consultora Imobiliária']]"); 
$count = $body->length;

$countTotalConsultores = $countTotalConsultores+$count;

echo "        Página atual:" .$current_page . "No. of agents " . $countTotalConsultores;

$current_page = $current_page+1;

if ($count < 1){
    break;

有人可以帮帮我吗?

已编辑:

您正在尝试查找具有两个不同值的文本节点。那永远不会匹配任何东西。这就像说给我夏天所有的日子,都是 100% 晴天和 100% 雨天。

像这样使用 or 而不是 and

"//*[text()[normalize-space() = 'consultor imobiliario' or normalize-space() ='Consultora Imobiliária']]"  

我想你在找

"//*[text()[contains(normalize-space(), 'consultor imobiliario') or contains(normalize-space(),'Consultora Imobil')]]"