ruckser Posted June 8, 2017 Share Posted June 8, 2017 (edited) 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 June 8, 2017 by Zane Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 8, 2017 Share Posted June 8, 2017 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"]' 1 Quote Link to comment Share on other sites More sharing options...
ruckser Posted June 8, 2017 Author Share Posted June 8, 2017 (edited) 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 June 8, 2017 by ruckser Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 8, 2017 Share Posted June 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
ruckser Posted June 8, 2017 Author Share Posted June 8, 2017 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 Quote Link to comment Share on other sites More sharing options...
ruckser Posted June 8, 2017 Author Share Posted June 8, 2017 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> Quote Link to comment Share on other sites More sharing options...
ruckser Posted June 8, 2017 Author Share Posted June 8, 2017 Any idea guys Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 8, 2017 Share Posted June 8, 2017 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. Quote Link to comment Share on other sites More sharing options...
ruckser Posted June 8, 2017 Author Share Posted June 8, 2017 That would be my last option, if I use ThingSpeak to retrieve data using the attribute I want it work with no problem too. Quote Link to comment Share on other sites More sharing options...
ruckser Posted June 9, 2017 Author Share Posted June 9, 2017 UPDATE: The codes are correct the problem is I was using older simple html dom, now the codes should look like this <?php include("advanced_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"); } ?> Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 9, 2017 Share Posted June 9, 2017 (edited) 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 June 9, 2017 by Jacques1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.