如何为html页面创建Regexp

本文关键字:创建 Regexp html | 更新日期: 2023-09-27 17:50:46

我有这个代码的html页面

<table class="data">
        <tr>
            <td class="head" >Time</td>
            <td class="head right" >Pref</td>
            <td class="head" >Name</td>
            <td class="head">Descr</td>
        </tr>
        <tr>
            <td colspan="4" class="date">
                2014.03.17
            </td>
        </tr>
        <tr valign="top" class="dat">
                    <td>22:02</td>
                    <td class="right">
                    3/2014
                     </td>
                <td>
                    <a href="/reports/id=34">
                    <b>Company Name</b>
                    </a>
                </td>
                <td>
                    <a href=/reports/view/id=34" target="_blank" class="th">
                    Description 
                        </a>
                    </td>
        </tr>
        <tr valign="top" class="date">
                    <td>21:16</td>
                    <td class="right">
                        8/2014
                    </td>
                    <td>
                        <a href="/reports/id=324">
                            <b>Company Name2</b>
                        </a>
                    </td>
                    <td>
                        <a href="reports/view/=324" target="_blank" class="th">
                        Description
                        </a>
                    </td>
            </tr>
................................
</table>

你能帮我创建regexp从表中提取数据。我需要这些数据21:16,8/2014,公司名称2,描述

谢谢。

如何为html页面创建Regexp

不要尝试用Regex解析HTML。你可能会走得相当远,但很容易把它搞砸,而且效果不好。它曾经经历过惨痛的教训。就像其他人在评论中提到的那样。看到:

https://stackoverflow.com/a/1732454/794380

你应该试试Html敏捷包:http://htmlagilitypack.codeplex.com

看这里https://stackoverflow.com/a/19871589/307976