0

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>';
}

2 Answers 2

4

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;
Sign up to request clarification or add additional context in comments.

Comments

3

Try this, a little italian guide, jquery documentation

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

$urls = $doc['a[href*="/phones/manufacturer/"]'];

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.