Jump to content

Fetching attribute inside DIV with Simple HTML Dom


ruckser

Recommended Posts

Hi everyone

 

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



<?php
    include("simple_html_dom.php");
    $html = file_get_html("https://sport.premierbet.com/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

 

Parse error: syntax error, unexpected '1' (T_LNUMBER) in C:\xampp\htdocs\Arb\test2.php on line 4

 

i tried to solve with no lucky , As the code look above can any one help me where am wrong? You can see div codes that i am referring in the pic i have attached.
Link to comment
Share on other sites

PHP tells you that your code is syntactically invalid. Now read the code:

"div=[data-gamename="1X2"]"

How exactly is PHP supposed to figure out where the string starts and where it ends? There are double quotes all over the place.

 

You need to write valid strings:

'div=[data-gamename="1X2"]'
Link to comment
Share on other sites

 

PHP tells you that your code is syntactically invalid. Now read the code:

"div=[data-gamename="1X2"]"

How exactly is PHP supposed to figure out where the string starts and where it ends? There are double quotes all over the place.

 

You need to write valid strings:

'div=[data-gamename="1X2"]'

Thanks for reply man, i tried to change but it display nothing, Now its look like this

 

<?php
    include('simple_html_dom.php');
    $html = file_get_html('https://sport.premierbet.com/tz/sport/1/#');
    foreach($html->find('div=[data-gamename=1X2]') as $a){
             echo $a->plaintext;
             echo nl2br('\n');
?>
Link to comment
Share on other sites

You said your code worked fine before you changed the attribute, but I very much doubt that.

 

This:

div=[data-gamename="1X2"]
  ^^^

doesn't look like a valid selector.

I dont think if there is a problem there because if i change look like this div=[class=outcome] will work like charm but if i change to that above it wont run  :  :

Link to comment
Share on other sites

Div code are like this

 

<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>
Link to comment
Share on other sites

What you are describing is nonsensical behavior from a third-party library which I don't use and which appearently hasn't been updated since 2012. Personally, I'm not interested in debugging this.

 

Either switch to a standard HTML library like DOMDocument. Or try finding the error yourself.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.