HTML Dom解析器获取第一个元素 [英] Html Dom parser get first element

查看:97
本文介绍了HTML Dom解析器获取第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 simple_html_dom php库从其他网站获取内容.

Hi i'm using simple_html_dom php library to get contents from other website.

我具有以下html结构,

I have below html structure,

<h1 class="nik_product_title" style="color: #000;">
  DSLR D7100
  <span class="new_big_parent">
    <span class="new_big_child">
      <span class="new_big_child1">new</span>
    </span>
  </span>
</h1>

使用

@$html->find ( 'div[class=nik_block_product_main_info_component_inner] h1',0)->plaintext;

但是我将输出为 DSLR + D7100new

如何仅获取第一个纯文本,即仅需获取 DSLR D7100

How to get only first plain text i.e, need to fetch only DSLR D7100

推荐答案

实际上,您可以使用以下方法实现这一目标:

You can actually get at that one with:

$html->find('h1 text', 0);

这篇关于HTML Dom解析器获取第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆