dongshun7312 2015-10-30 23:20
浏览 137
已采纳

如何使用PHP Simple HTML dom获取此文本?

Assuming I have this HTML Code in an HTML source:

<div class="info">
    <p><span class="strong">Score</span>4.32/5</p>
    <p><span class="strong">Type</span>TV</p>
    <p><span class="strong">Episodes</span>13</p>
    <p><span class="strong">Status</span>Ongoing</p>
    <p><span class="strong">Aired</span>Oct 3, 2015 - Dec 26, 2015</p>
    <p><span class="strong">Age</span>PG-13 - Teens 13 or older</p>
</div>

How do I use the PHP Simple HTML dom to get the text 4.32 from above? I tried

foreach($info_html->find('.strong') as $library) {
    $rating = $library->innertext;
    var_dump($rating);
}

But that only gives me the text "score", but I want 4.32.

  • 写回答

2条回答 默认 最新

  • douzhan1935 2015-10-31 01:20
    关注

    Maybe this will give you the result you are looking for:

    foreach($info_html->find('div.info p') as $library) {
        $rating = $library->find('text', 1)->innertext;
        var_dump($rating);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错
  • ¥15 Dell g15 每次打开eiq portal后3分钟内自动退出