简体   繁体   English

简单的HTML dom ul类

[英]simple html dom ul class

I am trying to get the content of ul tag with multiple class names. 我正在尝试使用多个类名来获取ul标签的内容。 The same syntax works for div tags but cant get it to work with the ul tag below. 相同的语法适用于div标签,但不能使其与下面的ul标签一起使用。 It just returns empty array. 它只是返回空数组。

<html>
  <div>
    <div>
      <div>
        <ul class="set-left farm margin-exclude">
          <li>
            <a href="#">Text</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</html>

Below just returns empty Array. 下面只是返回空数组。

$html->find('ul[class=set-left farm margin-exclude]');

这应该可以解决问题

$html->find('ul.set-left.farm.margin-exclude');

I have this working code at my end:- 我在结尾处有以下工作代码:-

file.txt:- file.txt的 -

<html>
  <div>
    <div>
      <div>
        <ul class="set-left farm margin-exclude">
          <li>
            <a href="#">Text</a>
          </li>
        </ul>
        <ul class="set-left farm margin-exclude">
          <li>
            <a href="#">Text2</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</html>

query.php:- query.php: -

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
include_once('simple_html_dom.php'); // this is parser file
$html = file_get_html('file.txt');


$level_items = $html->find('*[class="set-left farm margin-exclude"]');

foreach ( $level_items as $item ) {
   echo $item;
}

Output on browser:- http://i.share.pho.to/92745ee0_o.png 在浏览器上输出: -http : //i.share.pho.to/92745ee0_o.png

Note:- download parser file here:- https://sourceforge.net/projects/simplehtmldom/files/ 注意:-在此处下载解析器文件: -https : //sourceforge.net/projects/simplehtmldom/files/

You can use different way like:- 您可以使用其他方式,例如:

$html->find('ul.set-left');

OR 要么

$html->find('.set-left.farm.margin-exclude');

OR 要么

$html->find('*[set-left.farm.margin-exclude]');

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

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