html body.find,simple_html_dom找到TBODY和其他组件

我纠正你的HTML例子,除非你会说,它不是一个错误!

在此基础上,我们有:

只有一个img标签,所以我们可以直接搜索并拿到冠军$table->find('img',0)->title

其他所有想文本withing一个div标签,因此我们可以搜索所有div,然后使用循环打印其内容。

这是一个工作

$table = '

TEXT WHICH I NEED

2nd TEXT WHICH I NEED

3rd TEXT WHICH I NEED

4th TEXT WHICH I NEED

HREF which I need

TEXT which I need also

';

//Create a DOM object

$html = new simple_html_dom();

// Load HTML from a string

$html->load($table);

/

// Find img title

$imgTitle = $html->find('img',0)->title;

echo "IMG title: $imgTitle ";

// Find all divs

$divs = $html->find('div');

echo "DIV's content:";

// loop through all found divs and print their content

foreach($divs as $i => $div) {

echo "$i: " . $div->plaintext . "
";

}

// Clear DOM object

$html->clear();

unset($html);

输出

IMG title:

this is img which I need also

DIV's content:

0: TEXT WHICH I NEED

1: 2nd TEXT WHICH I NEED

2: 3rd TEXT WHICH I NEED

3: 4th TEXT WHICH I NEED

4: HREF which I need

5: TEXT which I need also

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值