使用简单HTML DOM解析器查找嵌套的选择器HTML元素

时间:2019-04-28 09:09:05

标签: php simple-html-dom

目前我有一个这样的DOM:

<div class="col-sm-4">
    <ul class="unstyled-list list-medium">
        <li><i class="fa fa-chevron-right fs-small"></i> ABCD </li>
        <li><i class="fa fa-chevron-right fs-small"></i> EFDG </li>
        <li><i class="fa fa-chevron-right fs-small"></i> WXYZ </li>
        <li><i class="fa fa-chevron-right fs-small"></i> TYUIOP </li>
        <li><i class="fa fa-chevron-right fs-small"></i> 12345 </li>
        <li><i class="fa fa-chevron-right fs-small"></i> 67890 </li>
    </ul>
</div>

然后我使用简单HTML DOM解析器通过我的代码获取“ i”标签的值:

$html = file_get_html('abc.com');
$list = $html->find('div[class="col-sm-4"]',0);
$list1 = $list->find('ul[class="unstyled-list list-medium"]',0);
foreach ($list1->find('li') as $li) {
    foreach ($li->find('i[class="fa fa-chevron-right fs-small"]',0) as $i) {
        echo $i;
    }
}

当我运行它时,它仍然会返回结果,但是还会出现类似以下错误:

Notice: Array to string conversion in C:\xampp\htdocs\index.php on line 25
Array
Notice: Array to string conversion in C:\xampp\htdocs\index.php on line 25
Array
Notice: Array to string conversion in C:\xampp\htdocs\index.php on line 25
Array
ABCD

Notice: Array to string conversion in C:\xampp\htdocs\index.php on line 25
Array86981i
Notice: Array to string conversion in C:\xampp\htdocs\index.php on line 25
Array
Notice: Array to string conversion in C:\xampp\htdocs\index.php on line 25
Array
Notice: Array to string conversion in C:\xampp\htdocs\index.php on line 25
Array
EFDG

我搜索起来很疯狂,但仍然不知道为什么我的foreach循环会返回这样的错误?

0 个答案:

没有答案