简体   繁体   English

使用简单的html dom获取无序列表和列表项中的DIV

[英]fetching DIV that are inside unordered list and list item with simple html dom

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? 我如何获得ulli内的DIV ,如下面的代码所示,在一个li内有很多DIV我应该使用哪种方法? 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 以下是我使用过的代码,但它们会提取所有li包括我不需要的li ,需要您考虑如何从<li class="single-event live">获取示例<div class="single-event__code"> <li class="single-event live">见下面的PHP和CSS代码

  <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>

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代码,我可以获取无序列表/列表项之外的所有对象,它们将显示在屏幕上,但是如果我更改并获取无序列表/列表中的数据,例如<div class="single-event__code">项目,将不会输出任何内容。

 <?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);

 }

Need your thoughts. 需要你的想法。

You might want to use PHP DOM with xpath like in the example For selection, you can use "li.single-event .single-event__code". 您可能希望像示例中那样将PHP DOM与xpath一起使用。要进行选择,可以使用“ 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. 这样,您将在li元素内获得所有带有“ single-event__code”类的div。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM