【发布时间】:2011-04-11 13:53:32
【问题描述】:
我处于以下情况。我正在尝试将杂乱的抓取 html 代码转换为漂亮整洁的 xml 结构。
抓取网站的部分 HTML 代码:
<p><span class='one'>week number</span></p>
<p><span class='two'>day of the week</span></p>
<table class='spreadsheet'>
table data
</table>
<p><span class='two'>another day of the week</span></p>
<table class='spreadsheet'>
table data
</table>
<p><span class='one'>another week number</span></p>
ETC
现在我想用 php 创建以下 xml 结构:
<week number='week number'>
<day name='day of the week'>
<data id='table data'>table data</data>
</day>
<day name='another day of the week'>
<data id='table data'>table data</data>
</day>
</week>
<week number='another week number'>
ETC
</week>
一直在尝试简单的 html dom 方法,但不知道如何获取下一个兄弟并检查它是一周中的新一天、新表数据还是新一周等。
当然,我也愿意接受其他解决方案。
谢谢。
干杯, 丹东
【问题讨论】:
标签: php html dom screen-scraping preg-match