PHP从目标URL提取特定的DIV
我正在使用简单的HTML DOM尝试从目标URL提取一个div及其所有内容,下面是我的代码:PHP从目标URL提取特定的DIV,php,dom,simple-html-dom,Php,Dom,Simple Html Dom,我正在使用简单的HTML DOM尝试从目标URL提取一个div及其所有内容,下面是我的代码: <?php require 'simple_html_dom.php'; $html = file_get_html('http://mozilla.org'); foreach($html->find('.accordion') as $element) echo $element . '<br>'; ?> 我的问题是,上面的代码只提取di
<?php
require 'simple_html_dom.php';
$html = file_get_html('http://mozilla.org');
foreach($html->find('.accordion') as $element)
echo $element . '<br>';
?>
我的问题是,上面的代码只提取div的纯文本。div中也有我需要提取的图像。如果我使用下面的代码,那么所有的图像都会被提取出来,但是页面中的其他内容也会被提取出来
<?php
require 'simple_html_dom.php';
$html = file_get_html('http://mozilla.org');
echo $html;
?>
所以我的问题是,如何使用第一位代码从.accordion
中提取内容+图像
谢谢您可以随时尝试
$imgs = array();
foreach($html->find('.accordion',0)->find('img') as $img){
$imgs[] = $img->src;
}
print_r($imgs);
这将使用.accordion
div中的所有图像链接填充$imgs
变量
:)上手风琴课上的每个li都通过css有背景图像,因此请检查此项以访问样式属性