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.