OK, this is driving me nuts. I'm trying to screen-scrape the following bit of seemingly trivial HTML with phpQuery:
<td><nobr>10-05-2009</nobr><br>06:10<br>17:35 -1</td>
The date is easy since it's wrapped in the nobr tag, so eg. $element[':first-child']->text()
does the trick. But how do I get my grubby mitts on the second bit of text?
CSS works on elements only, so nth-child(2),(3)
return the surrounding <br>
tags, not the text.
If I could XPath it, the second node in .//text()
would be gold. But apparently in phpQuery-land, the context for $element->xpath->query('.//text()')
is the document root, so I get every single piece of text in the entire document!
Ideas? All the solutions in How do I select text nodes with jQuery? appear to involve Javascript DOM operations, which are considerably less evil than PHP's terrible DOM API. Maybe just dumping the entire element to string and exploding it on <br>
is the way to go...