我正在使用此库:http://simplehtmldom.sourceforge.net/manual.htm
我有以下页面,我想在每一行中提取:
<div class="amx-form-entry-container">
<table style="font-size: 16px; color:#000">
<tbody><tr>
<td>Submitted by:</td>
<td>
Rami
</td>
</tr>
<tr>
<td>
Assignee:
</td>
<td> </td>
</tr>
<tr>
<td>
Subcategory:
</td>
<td> H: Documentation</td>
</tr>
<tr>
<td>
Description:
</td>
<td>Hello</td>
</tr>
<tr>
<td>
Case reference:
</td>
<td>
BEY/0517/4444
</td>
</tr>
<tr>
<td>
Status:
</td>
<td> Closed</td>
</tr>
<tr>
<td>
Created on:
</td>
<td> 19 May 2017</td>
</tr>
</tbody></table>
</div>
例如:
提交人:Rami
受让人:..
描述:你好
我已完成此代码:
$oDom = new simple_html_dom();
$dd=$oDom->load($result);
$test= $oDom->find("div[class='amx-module amx-mr-form-panel']",0);
echo $test;
但是它将输出打印为表格,如果我查看页面源代码,我会看到相同的代码。 - 我想要实现的是将每个元素打印在一行中。
答案 0 :(得分:0)
这是我的代码
$oDom->load($result);
$tables = $oDom->find('table');
$theData = array();
foreach($tables[0]->find('tr') as $row){
$rowData = array();
foreach($row->find('td') as $cell) {
$rowData[] = $cell->innertext;
}
$theData[] = $rowData;
}
echo "<pre>"; print_r($theData); echo "</pre>";
### Result ###
Array
(
[0] => Array
(
[0] => Submitted by:
[1] => Rami
)
[1] => Array
(
[0] => Assignee:
[1] =>
)
[2] => Array
(
[0] => Subcategory:
[1] => H: Documentation
)
[3] => Array
(
[0] => Description:
[1] => Hello
)
[4] => Array
(
[0] => Case reference:
[1] => BEY/0517/4444
)
[5] => Array
(
[0] => Status:
[1] => Closed
)
[6] => Array
(
[0] => Created on:
[1] => 19 May 2017
)
)