I am using phpquery to extract some data from a webpage. I need to identify the menu of the page. My implementation is to find each element that has sibilings > 0 and last-child is an "a"
. My code is:
foreach($this->doc['*'] as $tagObj){
$tag = pq($tagObj);
if(count($tag->siblings()) > 0){
if($tag->find(":last-child")->tagName === "a")
echo trim(strip_tags($tag->html())) . "<br/>";
}
}
However, I am not getting any output because of
$tag->find(":last-child")->tagName
which isn't returning anything. What would be the reason for this?
You can do it in reverse check for
a:last-child
:For example :
This will check for the
a
tag oflast-child
and you can get its content easily. May this help you.I don't know this library but perhaps something like this
Because
phpQueryObject
returned bypq
implements theIterator
and uses a public array$elements
to store all elements, we need to get the element using theget()
function, which returns aDOMElement
that is has thetagName
andnodeName
properties:Both properties will output the tag name that has the
test-span
class which of course isspan
.Maybe you should use :last instead of :last-child
According to the library Google Page: