S
S
Sergey Bard2017-04-28 18:33:03
PHP
Sergey Bard, 2017-04-28 18:33:03

How to parse link and meta using phpquery?

Hello. I work with phpquery , there is a task to parse canonical and meta robots

<link rel="canonical" href="site.com" />
<meta name="robots" content="noindex, follow">

I just can’t find an example of how to do this, in the net it’s only how to parse class, title, desc. etc., but there is nothing for my task (
function get_content($url){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}

    $url =  "site.com";
    $url =  get_content($url);
    $pQQ = phpQuery::newDocument($url);

$title = pq( 'link' );
foreach ($title as $par) {
    $link =  pq($par);
    echo $link->text().'<br>';    
}

I try to take all the link and meta, but it doesn’t find anything, if you look for h1, h2, then everything works and finds it, and if the link or meta is deaf, while everything is in the page code.
Can anyone please tell me if I am doing something wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-04-28
@serg_small_developer

1. Why reinvent the wheel with get_contents? There is also file_get_contents
2. You need to specify not the domain, but the URL (it starts with http)
3. Using the same $url variable for both the address and the content is a bad idea
4. Look for link and meta in $pQQ['head']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question