【发布时间】:2017-11-17 02:11:54
【问题描述】:
我想从抓取的文件中安排输出格式。
我想将它们全部放在一行中的输出文件。
对于分开每个td,我的预期输出如下:
<b>Nation / Area</b>(Name tag) <b>Detail</b>Address Telephone
(解释)“国家/地区”、“(名称标签)”、“4 个空格”、“详细信息”和 “地址电话”随后被列为我的预期输出。 总共有 5 个字段。
================================================ ===
我不知道如何处理这种情况。
这是页面HTML代码。
<table border='1' id='hi_hosts_table_id' cellspacing='0' cellpadding='4'>
<tr>
<td class='hi_table_header'><b>Nation / Area</b><br>(Name tag)</td>
<td class='hi_table_header'><b>Detail</b><br>Address<br>Telephone</td>
</tr>
</table>
这是我安排该输出文件的代码。
$absolute_path = '/home/hi/mycrawler/benchmark';
include($absolute_path.'/simple_html_dom/simple_html_dom.php');
$dom = file_get_html($absolute_path.'/'.$datetime.'benchmark.html');
#download the list
if ($dom->find('table[id=hi_hosts_table_id]'))
{
foreach($dom->find('table[id=hi_hosts_table_id]')->find('tr') as $row)
{
$location = $row->find('td',0)->plaintext;
$detail= $row->find('td',1)->plaintext;
echo "$location $detail\n";
}
} else {
#Pending match or not match
echo "No match. There are some problems.\n";
exit(0);
}
exit(0);
?>
【问题讨论】:
-
您是否只想在 $location 和 $detail 之间使用一个制表符??
-
如果你想在 1 行输出,不要在
中使用
。这将强制输出转到下一行。 -
@Nic3500 谢谢。那一刻我对此很愚蠢。谢谢你的评论。我的名声比较低。我希望你能投票给这个帖子。感谢您的慷慨帮助。
标签: php web-crawler