本文介绍了如何使用phpquery查找标签名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phpquery从网页提取一些数据。我需要识别页面的菜单。我的实现是找到每个具有相同参数> 0的元素,last-child是一个a。我的代码是:

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

哪些没有返回任何东西。这是什么原因?

which isn't returning anything. What would be the reason for this?

推荐答案

我不知道这个图书馆,但也许这样的样子

I don't know this library but perhaps something like this

$siblings = $tag->siblings();
if (($siblingCount = count($siblings)) && $siblings[$siblingCount - 1]->tagName === 'a') {
    echo ...
}

这篇关于如何使用phpquery查找标签名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 16:23