FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

How can I scrape json-ld schema? #365

Open xsaad67 opened 5 years ago

xsaad67 commented 5 years ago

Hello, How can i scrape the content inside json-ld schema. I've printed all the information through ->text() but not getting <script type="application/ld+json"> Is there any other possible option to extract the information of schema json?

abomine commented 4 years ago

Hey, i am facing the same problem over here (a year after you haha) if you found a solution (or a hint) please let me know i need to scrap a json+ld content ...

gnumoksha commented 4 years ago
$jsonLdElements = $crawler->filter('script[type="application/ld+json"]')->each(function ($node) {
            return $node->text();
        });

$element = \json_decode($jsonLdElements[0]);