Fetching DIV attribute using Simple HTML Dom

Hi everyone

I am having difficult with this issue using Simple_HTML_DOM, As you see the my simple codes

    $html = file_get_html('https://sport.premie...tz/sport/1/#');
    foreach($html->find('div=[data-gamename="1X2"]') as $a){
             echo $a->plaintext;
             echo nl2br('\n');

From the above code if i want retrieve values of <div class="games"></div> it will work good and if i want to retrieve values from <div class="wrap"></div> it will work good too and make to make a record this second div is inside the first div of <div class="games"> there it come another one inside the second div of <div class="wrap"></div> it is called <div class="outcome active"></div> My problem start here if i want to retrieve data from lets say <div class="outcome active"> it will work like charm but if i change the attribute lets say <data-gamename="1X2"> like in example above it will not work and and bring this error

i tried to solve with no lucky , As the code look above can any one help me where am wrong? You can see div code are in this format

<div class="games">==$0
   <div class="wrap">
           <div class="outcome" onclick="addBet(this)" id="outcome-225162629" data-gameid="61158022" data-outcomeid="225162629" data-gamename="1X2"    data-eventname="Benevento Calcio - Carpi FC" data-eventcodeid="137" data-gamename="1X2">2.11</div>

Any idea guys?

Hi mwambembela welcome to the forum

I am unfamiliar with “simple_html_dom”, I assume that is third party code?

You say that $a->plaintext works for some but not others. From how I understand PHP syntax, that would be an object property that from what I see wouldn’t be there anytime. So I’m obviously missing something.

What is “simple_html_dom” and does it have documentation?

1 Like

Thanks Mittineague, Simple HTML Dom is a parser providing a very easy way to handle HTML elements its API can be found here

download it its size is around 336KB you will find all the info inside the file including its API

Here is the solution, I was using old version of HTML Dom, the code should look like this.

<?php include('advanced_html_dom.php'); $html = file_get_html('https://sport.premie...tz/sport/1/#'); foreach($html->find('div=[data-gamename="1X2"]') as $a){ echo $a->plaintext; echo nl2br('\n'); } ?>
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.