0

So I'm trying to fetch some open graph data with domcrawler using the php package "Goutte".

Specifically, I'm trying to extract the og:image.

$goutteClient = new Client();
$guzzleClient = new GuzzleClient(array(
    'timeout' => 15,
));

$goutteClient->setClient($guzzleClient);

try {
    $crawler = $goutteClient->request('GET', $url);
    $crawlerError = false;
} catch (RequestException $e) {
    $crawlerError = true;
}


$OGimage = $crawler->filterXPath("//meta[@name='image']")->attr('content');
//find open graph image
dd($OGimage);

So if try this out with this URL, for example:

https://www.bbc.com/sport/football/49421006

it will return an empty string.

However, if I put in meta[@name='description'] instead of image, it will return

"France international Franck Ribery joins Serie A side Fiorentina on a free transfer after leaving Bayern Munich in the summer."

But when I view the source of this page, there's clearly an og:image tag.

Why is this returning empty but description does not? Worth noting that ALL of the open graph tags are returning empty strings with this EXCEPT description, which works just fine.

Felix
  • 2,532
  • 5
  • 37
  • 75
  • 1
    Have you tried with `og:image`? The page has `description` and `og:description`, so you're probably pulling the `description`. Also, `og:image` is a property, not a name. – aynber Aug 21 '19 at 19:33
  • Ah, duh. Switching it to $crawler->filterXPath("//meta[@property='og:image']")->attr('content'); did the trick. Thanks! – Felix Aug 21 '19 at 19:42

0 Answers0