javascript - how can get content json from <scriptscript type="application/ld+json"> -
i can't find api vine page content's title, description , image. json in body of page in script tag: . how content (the json) of script tag using php can parsed?
vine page:
https://vine.co/v/igo3ebixdli
from page source
<script type="application/ld+json"> { "@context": "http://schema.org", "@type": "socialmediaposting", "url": "https://vine.co/v/igo3ebixdli", "datepublished": "2016-03-01t00:58:35", "author": { "@type": "person", "name": "motoraddicts\u2122", "image": "https://v.cdn.vine.co/r/avatars/39fefed72b1242718633613316096_pic-r-1439261422661708f3e9755.jpg.jpg?versionid=lpjquq4kmtiplu3idbxw4fipgjepc6fw", "url": "https://vine.co/u/989736283540746240" }, "articlebody": "mmm... black black blaaaaack!! \ud83d\ude0d ( drift \u53d1 )", "image": "https://v.cdn.vine.co/r/videos/98c3799a811316254965085667328_sw_webm_14567938452154dc600dbde.webm.jpg?versionid=wpuaqvdxnpwf7kjsgao21hoddooc3ecl", "interactioncount": [{ "@type": "userinteraction", "userinteractiontype": "http://schema.org/userlikes", "value": "1382" }, { "@type": "userinteraction", "userinteractiontype": "http://schema.org/usershares", "value": "368" }, { "@type": "userinteraction", "userinteractiontype": "http://schema.org/usercomments", "value": "41" }, { "@type": "userinteraction", "userinteractiontype": "http://schema.org/userviews", "value": "80575" }], "sharedcontent": { "@type": "videoobject", "name" : "mmm... black black blaaaaack!! \ud83d\ude0d ( drift \u53d1 )", "description" : "", "thumbnailurl" : "https://v.cdn.vine.co/r/videos/98c3799a811316254965085667328_sw_webm_14567938452154dc600dbde.webm.jpg?versionid=wpuaqvdxnpwf7kjsgao21hoddooc3ecl", "uploaddate" : "2016-03-01t00:58:35", "contenturl" : "https://v.cdn.vine.co/r/videos_h264high/98c3799a811316254965085667328_sw_webm_14567938452154dc600dbde.mp4?versionid=w7uglpytj5lwevusxah1bt2vuk8qe0qv", "embedurl" : "https://vine.co/v/igo3ebixdli/embed/simple", "interactioncount" : "82366" } } </script>
what after this?
$html = 'https://vine.co/v/igo3ebixdli'; $dom = new domdocument; $dom->loadhtml($html);
when go page, don't see script tag referencing. found page has one, , how it:
<?php $html = file_get_contents('https://tv-sewingcenter.com'); $dom = new domdocument; libxml_use_internal_errors(true); $dom->loadhtml($html); $jsons = array(); $scripts = $dom->getelementsbytagname('script'); if( ! empty( $scripts ) ) { foreach( $scripts $script ) { if( $script->hasattribute('type') && $script->getattribute('type') == 'application/ld+json' ) { $jsons[] = json_decode($script->nodevalue, true); } } if( ! empty( $jsons ) ) { foreach( $jsons $json ) { echo '<pre>'; print_r( $json ); echo '</pre>'; } } }
Comments
Post a Comment