2016-05-03 16 views
1

Im bekommen mit Goutte\Client in Laravel 5.2 und es scheint, dass es nicht den Meta-Tags Inhalt bekommen kann, aber den Titel bekommen, Links, etc.Laravel Goutte nicht Meta-Tags

Das gibt leere Zeichenfolge zurück.

$parse = $htmlParser->request('GET', 'http://www.sample.com'); 
$parse->filter('meta'); 

Ausgang:

private 'nodes' => 
    array (size=20) 
     0 => 
     object(DOMElement)[289] 
      public 'tagName' => string 'meta' (length=4) 
      public 'schemaTypeInfo' => null 
      public 'nodeName' => string 'meta' (length=4) 
      public 'nodeValue' => string '' (length=0) 
      public 'nodeType' => int 1 
      public 'parentNode' => string '(object value omitted)' (length=22) 
      public 'childNodes' => string '(object value omitted)' (length=22) 
      public 'firstChild' => null 
      public 'lastChild' => null 
      public 'previousSibling' => null 
      public 'nextSibling' => string '(object value omitted)' (length=22) 
      public 'attributes' => string '(object value omitted)' (length=22) 
      public 'ownerDocument' => string '(object value omitted)' (length=22) 
      public 'namespaceURI' => null 
      public 'prefix' => string '' (length=0) 
      public 'localName' => string 'meta' (length=4) 
      public 'baseURI' => null 
      public 'textContent' => string '' (length=0) 

Diese den Titel zurückgibt.

$parse = $htmlParser->request('GET', 'http://www.sample.com'); 
$parse->filter('title'); 

Ausgang:

private 'nodes' => 
    array (size=1) 
     0 => 
     object(DOMElement)[289] 
      public 'tagName' => string 'title' (length=5) 
      public 'schemaTypeInfo' => null 
      public 'nodeName' => string 'title' (length=5) 
      public 'nodeValue' => string 'Test title' (length=36) 
      public 'nodeType' => int 1 
      public 'parentNode' => string '(object value omitted)' (length=22) 
      public 'childNodes' => string '(object value omitted)' (length=22) 
      public 'firstChild' => string '(object value omitted)' (length=22) 
      public 'lastChild' => string '(object value omitted)' (length=22) 
      public 'previousSibling' => string '(object value omitted)' (length=22) 
      public 'nextSibling' => string '(object value omitted)' (length=22) 
      public 'attributes' => string '(object value omitted)' (length=22) 
      public 'ownerDocument' => string '(object value omitted)' (length=22) 
      public 'namespaceURI' => null 
      public 'prefix' => string '' (length=0) 
      public 'localName' => string 'title' (length=5) 
      public 'baseURI' => null 
      public 'textContent' => string 'Test title' (length=36) 
+1

Haben Sie das versucht? http://stackoverflow.com/questions/22674916/how-to-get-meta-description-content-using-goutte –

Antwort

0

@moisesgallego auf this Post konnte meine Frage beantworten, obwohl mit ihm herumspielen konnte ich eine andere als gut finden. Im Grunde durchläuft es alle Meta-Tags und gibt den Namen und den Inhalt als Array zurück.

$crawler = $client->request('GET', 'https://stackoverflow.com/'); 
$meta = $crawler->filter('meta')->each(function($node) { 
    return [ 
     'name' => $node->attr('name'), 
     'content' => $node->attr('content'), 
    ]; 
});