I am using simple html dom to parse a link that contains two script tags with type=application/ld+json.
The target website structure is like below,
// tag that I want to parse
<script type="application/ld+json">
Some JSON Data
</script>
// tag that I **do not want** to parse
<script type="application/ld+json">
Some JSON Data
</script>
Now as I showed above I just want to parse the data inside the first , For this I am using following code
foreach($html->find('script[type="application/ld+json"]',0) as $name)
{
echo $name->innertext;
}
As I am trying to extract the first occurrence of by specifying "0" in find() function but that give me the following error.
Trying to get property of non-object in C:\xampp\htdocs\htmldom\example\example_basic_selector.php on line 14
Anyone knows what I am doing wrong or how can I fix this? Thanks
,0, it works and shows you the inner text of both of those script elements? If not, then that would mean your selector doesn’t match the elements to begin with.find('foo')returns an array,find('foo', 0)returns one specific element. Does$script = $html->find('script[type="application/ld+json"]',0); echo $script->innertext;get you what you need?