有一个html页面,它包含一个块:
<table class="tborder" cellpadding="6" cellspacing="1" border="0" width="100%" align="center">
<tr>
<td class="tcat" colspan="2">
Some regular text <span class="normal">the desired text 1</span>
</td>
</tr>
<tr>
<td class="alt1" colspan="2">
<span class="smallfont"><a href="page.php?u=00001">link1</a>, <a href="page.php?u=00002"><i><b><font color="#006400">link2</font></b></i></a></span>
</td>
</tr>
</table>
帮我解析简单的html dom库或正则表达式,这样只会在这里推断:
the desired text 1 <span class="smallfont"><a href="page.php?u=00001">link1</a>, <a href="page.php?u=00002"><i><b><font color="#006400">link2</font></b></i></a></span>
如果我这样做:
<?
include 'simple_html_dom.php';
$html = file_get_html('http://some-url.com/power.html');
foreach($html->find('td[class="tcat"]') as $element1)
echo $element1. '<br>';
foreach($html->find('span[class="smallfont"]') as $element2)
echo $element2. '<br>';
?>
因此,随着必要的数据也显示在页面上显示的更相似的元素。 (使用相同的参数'td class =“tcat”'和'class =“smallfont”') 我需要的只是推断:
the desired text 1 <span class="smallfont"><a href="page.php?u=00001">link1</a>, <a href="page.php?u=00002"><i><b><font color="#006400">link2</font></b></i></a></span>
答案 0 :(得分:2)
关于knowing css:
echo $html->find('td.tcat span', 0)->text();
echo $html->find('span.smallfont', 0);
//the desired text 1 <span class="smallfont"><a href="page.php?u=00001">link1</a>, <a href="page.php?u=00002"><i><b><font color="#006400">link2</font></b></i></a></span>