从HTML表格行列中提取数据 [英] Extract data from HTML table row column
本文介绍了从HTML表格行列中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从PHP的HTML表中提取数据.数据采用这种格式
How to extract data from HTML table in PHP. The data is in this format
表1
<tr><td class="body" valign="top"><a href="example"><b>DATA</b></a></td><td class="body" valign="top">Data_Text</td></tr>
表2
<tr><th><div id="Data">Data</div></th><td>Data_Text_1</td><td>Data_Text_2</td></tr>
表3
<tr><td width="120"><a href="example" target="_blank">DATA</a></td><td>Data_Text</td></tr>
我想获取数据& 3个表中的 Data_Text或(Data_Text_1& Data_Text_2).
我用过
I want to get the Data & Data_Text or (Data_Text_1 & Data_Text_2) from the 3 tables.
I've used
$html = file_get_contents($link);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$nodes = $xpath->query('//td[]');
$nodes2 = $xpath->query('//td[]');
但是它无法显示任何数据!
But it cant show any data !
我将在后天为这个问题提供悬赏
推荐答案
使用 simplehtmldom.php ...
<?php
include 'simple_html_dom.php';
$html = file_get_html('thetable.html');
$rows = $html->find('tr');
foreach($rows as $row) {
echo $row->plaintext;
}
?>
或使用'td'...
or use 'td'...
<?php
include 'simple_html_dom.php';
$html = file_get_html('thetable.html');
$cells = $html->find('td');
foreach($cells as $cell) {
echo $cell->plaintext;
}
?>
这篇关于从HTML表格行列中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文