XPATH - 多个 URL [英] XPATH - Multiple Url's

查看:53
本文介绍了XPATH - 多个 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码,可以统计以下词出现在网址consultor imobiliario、Consultora Imobil和Consultor Imobil上的重复次数:

The code bellow, can count the number of times that the following words appearing on the URL consultor imobiliario , Consultora Imobil and Consultor Imobil repeats:

    <?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once dirname(__FILE__).'/../public_html/include/functions.php';
require_once dirname(__FILE__).'/phpQuery.php';
//header('Content-Type:application/json');

//Decisoes e Solucoes - Consultores

$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);
$tables = $xpath->query("//*[text()[contains(normalize-space(), 'consultor imobiliario') or contains(normalize-space(),'Consultora Imobil') or contains(normalize-space(),'Consultor Imobil')]]");
$count = $tables->length;

$countTotalConsultores = $countTotalConsultores+$count;

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

$current_page = $current_page+1;

if ($count < 1){
    break;
}
}

如何使用此代码为此字词搜索计数添加多个 URL?

How can I add more than one URL for this Words searching count with this code?

我想在以下网址中搜索:

I want to search in this following url's:

https://decisoesesolucoes.com/agencias/albergaria/consultores?page=
https://decisoesesolucoes.com/agencias/ABRANTES/consultores?page=
https://decisoesesolucoes.com/agencias/albufeira/consultores?page=

有人可以帮我吗?

谢谢

推荐答案

你为什么不在那些 url 上循环?如果你想计数,你可以使用这个 XPATH 查询

Why don't you loop on those url ? If you want to count you can use this XPATH query

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

这篇关于XPATH - 多个 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆