DOMXPath $html->query('//p[@class="myclass"]/a')->item(0); is not working.
Here is the HTML:
<p class="username">
<img src="http://static1.tryal.com/img/b.gif" onclick="lalalaa()" class="a12s_iYblt4hN_DkIt_GoiyOtu8 opsi" />
<b>
<a href="/about"><b>Lalala.</b></a>
</b>
</p>
$name = $html->query('//p[@class="username"]/a')->item(0)->nodeValue;
//This doesn't return the name "Lalala.";
$name = $html->query('//p[@class="username"]')->item(0)->nodeValue;
//This works just fine.
Why isn’t this tree working? Am I typing it wrong?
Thank you very much in advance.
The xpath you have specified didn’t provide any result (or an result with no elements to be precise). You can fix that by not letting the
belement slip through:or by not making
aa direct/immediate child frompbut somewhere deeper as well (descendant of, double slash//in xpath):