【问题标题】:DOM Xpath object -> $variableDOM Xpath 对象 -> $variable
【发布时间】:2021-08-17 23:57:36
【问题描述】:

这是我的html

<p class="description-update"> <span>Alternative: </span>나 혼자만 레벨업
<br> <span>View: </span>262343066 views
<br> <span>Author(s): </span>Sung-Lak Jang
<br> <span>Artist(s): </span>a
<br> <span>Genre: </span>  <a href="http://kissmanga.nl/mangas/action">Action </a>, <a href="http://kissmanga.nl/mangas/adventure"> Adventure </a>, <a href="http://kissmanga.nl/mangas/fantasy"> Fantasy </a>, <a href="http://kissmanga.nl/mangas/shounen"> Shounen </a>, <a href="http://kissmanga.nl/mangas/webtoons"> Webtoons</a>,
<br> <span>Type: </span>b
<br> <span>Release: </span>c
<br> <span>Status: </span> Ongoing
<br><span id="bookmark"> <a class="btn-success btn btn_bookmark" href="#" onclick="addBookmark(9492,174881);return false;"> <i style="color: #fff" class="fa fa-flag"></i> <span style="color: #fff">Bookmark</span> 
</a>
</span> <span id="rmbookmark" class="display_bookmark"> <a class="btn-danger btn btn_rmbookmark" href="#" onclick="rmBookmark(9492);return false;"> <i style="color: #fff" class="fa fa-times"></i> <span style="color: #fff">Remove Bookmark</span> 
</a>
</span>

这是我的 php

$alternative = 'nextSibling->nodeValue';
$info = $xpath->query('.//*[contains(concat(" ",normalize-space(@class)," ")," description-update ")]/span');
echo $info->item(1)->nextSibling->nodeValue;
echo $info->item(1)->$alternative;

第一个回显输出是 262343066 次浏览,这正是我想要的。但是在第二个回声中我得到了这个错误

Undefined property: DOMElement::$nextSibling->nodeValue

如何修复第二个回显,使输出为 262343066 次观看

【问题讨论】:

    标签: php dom xpath


    【解决方案1】:

    是的,它现在可以工作了

    $alternative = explode('->','nextSibling->nodeValue');
    $info = $xpath->query('.//*[contains(concat(" ",normalize-space(@class)," ")," description-update ")]/span');
    echo $info->item(1)->nextSibling->nodeValue; //262343066 views (WORK)
    echo $info->item(1)->{$alternative[0]}->{$alternative[1]}; //262343066 views (WORK)
    

    【讨论】:

      猜你喜欢
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      • 2020-06-28
      • 2012-03-29
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多