phpphpquery

PHPQuery - get all links of contains specific url page


I am trying to get all links of contains specific url page on a given page using PHPQuery. I am using the PHP support syntax of PHPQuery.

include_once 'phpQuery.php';
$url = 'http://www.phonearena.com/phones/manufacturer/';
$doc = phpQuery::newDocumentFile($url);

$urls = $doc['a'];

foreach ($urls as $url) {
    echo pq($url)->attr('href') . '<br>';
}

The code above works . But it shows all the links I want to show only those containing "/phones/manufacturer/". I tried this but it shows nothing:

include_once 'phpQuery.php';
$url = 'http://www.phonearena.com/phones/manufacturer/';
$doc = phpQuery::newDocumentFile($url);

$urls = $doc['a'];

foreach ($urls as $url) {
    echo pq($url)->attr('href:contains("/phones/manufacturer/")') . '<br>';
}

Solution

  • Use below coding get all urls from that site,

            $doc = new DOMDocument();
                    @$doc->loadHTML(file_get_contents('http://www.phonearena.com/phones/manufacturer/'));
    
                    $ahreftags = $doc->getElementsByTagName('a');
    
                        foreach ($ahreftags as $tag) {
                            echo "<br/>";
                            echo $tag->getAttribute('href');
                            echo "<br/>";
                        }
    
    
    exit;