1 回答

TA贡献1818条经验 获得超3个赞
在您的示例代码中,您有
echo $x = $html->find('h2[class="section-heading"]',1)->outertext;
当您find()使用第二个参数 1 调用时,这只会返回 1 元素。相反,如果您找到所有这些-您可以对它们做任何您需要的事情...
$list = $html->find('h2[class="section-heading"]');
foreach ( $list as $item ) {
echo $item->outertext . PHP_EOL;
}
我刚刚测试的完整代码是......
include(__DIR__."/simple_html_dom.php");
$html = file_get_html('http://campaignstudio.in/');
$list = $html->find('h2[class="section-heading"]');
foreach ( $list as $item ) {
echo $item->outertext . PHP_EOL;
}
这给出了输出......
<h2 class="section-heading text-white">We've got what you need!</h2>
<h2 class="section-heading">At Your Service</h2>
<h2 class="section-heading">Let's Get In Touch!</h2>
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报