我使用以下 PHP 代码成功解析了一个动态表:
$docH = new DOMDocument();
$docH->loadHTMLFile($url);
//get everything inside the body element:
$bodyH = $docH->getElementsByTagName('body')->item(0);
foreach ($bodyH->childNodes as $childNode) {
echo $docH->saveHTML($childNode);
}
解析的 HTML 表:
<table>
<tr>
<td>5CG</td>
<td>aass</td>
<td>sxs</td>
<td>sx</td>
<td>EK</td>
<td></td>
<td>72</td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
<td></td>
<td>5AH.</td>
<td>ds</td>
<td>d</td>
<td>sdf</td>
<td>sdfsdf aus</td>
<td></td>
</tr>
<tr>
<td>6CG</td>
<td>3.</td>
<td>sfd</td>
<td></td>
<td>scs</td>
<td>das aus</td>
<td>a</td>
</tr>
<tr>
<td>7DG</td>
<td>6.</td>
<td>s</td>
<td>s</td>
<td>sD</td>
<td>sdsa.</td>
<td></td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
<tr>
<td>7DG, 7CG, 7CR</td>
<td>6.</td>
<td>NsdR</td>
<td>s</td>
<td>SP</td>
<td>fasdlt aus</td>
<td>s</td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
<tr>
<td>9BR</td>
<td>6.</td>
<td>FEI</td>
<td>sa</td>
<td>DE</td>
<td>fasdad aus</td>
<td></td>
</tr>
<tr>
<td>9AR, 9BR, 9CR</td>
<td>62.</td>
<td>BEH</td>
<td></td>
<td>sd</td>
<td>fasda aus</td>
<td></td>
</tr>
<tr>
<td></td>
<td>6.</td>
<td>MLR</td>
<td></td>
<td>FdR</td>
<td>fsdfaus</td>
<td></td>
</tr>
<tr>
<td>E10C</td>
<td>6.</td>
<td>sdf</td>
<td>d</td>
<td>d</td>
<td>fsdfs aus</td>
<td></td>
</tr>
<tr>
</table>
但我的目标是通过仅询问第一个元素中包含一些文本的元素来显示用户想要的表格内容,直到<tr>
另一个元素首先具有不同的内容。<td>
<tr>
<tr>
<td>
例如:如果用户在输入字段中输入“9BR”,我只想让他看到:
9BR 6. FEI sa DE fasdad aus 9AR, 9BR, 9CR 62. BEH sd fasda aus 6. MLR FdR fsdfaus
如果他输入 5CG:
<tr>
<td>5CG</td>
<td>aass</td>
<td>sxs</td>
<td>sx</td>
<td>EK</td>
<td></td>
<td>72</td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
或者如果 6CG 只是:
<tr>
<td>6CG </td>
<td>3. </td>
<td>sfd </td>
<td> </td>
<td>scs </td>
<td>das aus</td>
<td>a </td>
</tr>