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.
Edited by Zane
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"]'
  • Like 1
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');
?>
Edited by ruckser
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

I still have no idea why you would want to use an abandoned library which may have plenty of other bugs, and why you insist on using invalid selectors which only that library accepts (whether that's intentional or a bug).

Edited by Jacques1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.