Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP从目标URL提取特定的DIV_Php_Dom_Simple Html Dom - Fatal编程技术网

PHP从目标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

我正在使用简单的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>';
?>

我的问题是,上面的代码只提取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有背景图像,因此请检查此项以访问样式属性