user3210416
user3210416

Reputation: 804

simple html dom extracting table by its id

I'm using simple html dom in php to extract a table depending on its id. I have done this without any issues when the id doesn't involve any characters like hyphens(-). I suspect it is due to a hyphen because I used the same code with an id with no hyphens and no trouble receiving the data. The data I want to extract is also in a tab that is hidden, does this effect the process?

Here is my code

<?php

include('simple_html_dom.php');

//Insert the url you want to extract data from
$html = file_get_html('http://espnfc.com/team/_/id/359/arsenal?cc=5739');

$i = 0;
$dataInTable = true;

while($dataInTable){

    if($html->find('div[id=ui-tabs-1] table tbody', 0)->children(0)->children($i)){

            for($j=0;$j<3;$j++){

                if($html->find('div[id=ui-tabs-1] table tbody', 0)->children(0)->children($i)->children($j)){
                    $gk[] = $html->find('div[id=ui-tabs-1] table tbody', 0)->children(0)->children($i)->children($j)->plaintext;
                }else{
                $dataInTable = false;
                }
            }

            //else if nothing is in the next cell return false.
        }else{
            $dataInTable = false;
        }


    $i+=2;
}
var_dump($gk);

?>

Here is the HTML content enter image description here

Upvotes: 1

Views: 531

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117334

When you take a look at the source(not via dev-tools, use browser->viewsource) of http://espnfc.com/team/_/id/359/arsenal?cc=5739 you'll not see anything with the ID ui-tabs-1

This element has been created via javascript(I guess jQueryUI-tabs)

simple_html_dom parses HTML but did not evaluate javascript, so the answer is:

You can't select this element

Upvotes: 2

Related Questions