kiranshiv
kiranshiv

Reputation: 23

Fetch Content from A Div id using PHP Simple HTML DOM Parser

I have following html code

<div id="b_changetext" class="FL gL_13 PT15"> <span class="gr_15 uparw_pc"><strong>5.80</strong></span> (+2.28%)</div>

I wanted to extract content (+2.28%) Tried following code

foreach($html->find('div[n_changetext]') as $e){
      echo $e->innertext . '<br>';
    echo "wwwwww";
}

On running it does not enter the for loop . ( "wwwwww" is not displayed)

Can anyone please suggest a solution

Upvotes: 1

Views: 1320

Answers (1)

Quentin
Quentin

Reputation: 944568

div[n_changetext] finds elements with an n_changetext attribute (which is not valid in HTML).

To find an element with a given id you must specify that the name of the attribute is id and specify the value.

The value, in your example, starts with a b not an n:

find('div[id=b_changetext]')

Upvotes: 1

Related Questions