dsogx84602 2017-07-01 15:01
浏览 210
已采纳

如何使用php简单的html dom或Curl从div中抓取HTML标签

Here is an Example of what i want to do Example:

<div class='room'>
<h1>This is a h1</h1>
<p>This is a Paragraph</p>
<h2>This is h2</h2>
</div>

From the above emaple I would like to scrap data and tags in arrays. In the result I would like an array containing: arr = [h1,p,h2]; and another array: arr2 = [This is h1,This is paragraph,This is h2]

  • 写回答

4条回答 默认 最新

  • duanchi0897 2017-07-01 22:05
    关注
    $str = <<<EOF
    <div class='room'>
    <h1>This is a h1</h1>
    <p>This is a Paragraph</p>
    <h2>This is h2</h2>
    </div>
    EOF;
    
    $html = str_get_html($str);
    
    foreach($html->find('.room *') as $el){
      $arr[] = $el->tag;
      $arr2[] = $el->text();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑