使用简单的html dom获取无序列表中的DIV和列表项 [英] fetching DIV that are inside unordered list and list item with simple html dom

查看:201
本文介绍了使用简单的html dom获取无序列表中的DIV和列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取 ul li DIV $ c>像下面的代码所示,在单个里面有很多的 DIV 我应该使用什么方法?有下面我使用的代码,但他们获取所有 li 包括我不需要的,需要你的想法如何获得示例< div class =single-event__code> < li class =single-event live> 见下面的php和css代码

How can i get DIV that are inside ul and li like the below codes what shows, there is alot of DIV inside a single li what method should i use? there is codes i have used below but they fetch all li including those i don't need, need your thought how can i obtain example <div class="single-event__code"> from <li class="single-event live"> see below php and css codes

  <div class="app_content">
  <ul class="js-events-container">...</li>
    <li class="single-event live">...</li>
    <li class="single-event live">...</li>
    <li class="single-event live">...</li>
    <li class="single-event live">...</li>
    <li class="single-event live">
     ::before
     //First DIV of li
    <div class="single-event__code">
    Event Code: <strong>96441</strong>
               </div>
        <div class="single-event__time">
            <span class="score js-score">LIVE</span>
            <span class="time js-timer"></span>
            </div>
        <div class="single-event__players">
       <a href="/sportsbook/SOCCER/BRAZIL_SERIE_D/400953/">
        AA Portuguesa RJ <span> v </span> Audax SP </a>
                 </div>
       <div class="single-event__bets three markets">
    <div class="single-event__bets__container js-bets-container">
                <div class="single-event__bets__price">
                     1.02
                      </div><div class="single-event__bets__price">
                     81.00
                      </div><div class="single-event__bets__price">
                     101.00
                      </div></div>
    <div class="single-event__bets__more"><a href="/sportsbook/SOCCER/BRAZIL_SERIE_D/400953/" data-markets="+18">+<span>+18</span></a></div>
        </div>
   ::after
    </li>

    <li class="single-event live">...</li>
    <li class="single-event live">...</li>
    <li class="single-event live">...</li>
    <li class="single-event live">...</li>

更新
使用以下PHP代码,我可以获取所有外部无序列表/列表项,它们将显示在屏幕上,但如果我更改并获取无序列表/列表示例中的数据< div class =single-event__code> 项目它将不会输出任何内容。

UPDATE With this below PHP codes i can fetch all objects that are outside unordered list/list item and they will be displayed on screen but if i change and fetch data that are inside unordered list/list example <div class="single-event__code"> item it will output nothing.

 <?php

$html = file_get_contents('https://www.mkekabet.com/sportsbook/SOCCER/');
$dom = new DOMDocument();
 $internalErrors = libxml_use_internal_errors(true);
 $dom->loadHTML($html);
 libxml_use_internal_errors($internalErrors);
 $xpath = new DOMXPath($dom);

 $codeList = $xpath->query('//div[@class="app_content"]');
   foreach ($codeList as $codeDiv){
    var_dump($codeDiv->textContent);

 }

需要你的想法。

推荐答案

您可能想要使用PHP DOM与xpath,如示例
要进行选择,可以使用li.single-event .single-event__code。
这样你就可以得到所有的div,里面都有li元素中的single-event__code类。

You might want to use PHP DOM with xpath like in the example For selection, you can use "li.single-event .single-event__code". In this way you will get all the divs with the class "single-event__code" that are inside li elements.

这篇关于使用简单的html dom获取无序列表中的DIV和列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆