如何读入&#39; onmouseover&#39;使用C#和HTMLAgilityPack <table> </table>的事件

时间:2014-10-20 00:45:45

标签: c# html-agility-pack

如何使用C#和HTMLAgilityPack阅读<table>onmouseover个事件?

标记代码:

<a href="#" class="chan_live_not_free" onclick="return false;" onmouseover="return overlib('
    <table>
        <tr class=fieldRow>
            <td class=posH_col width=40>
                <strong>pos</strong>
            </td>
            <td class=rest_col width=90>
                <strong>satellite</strong>
            </td>
            <td class=freqH_col width=50>
                <strong>freq</strong>
            </td>
            <td class=rest_col width=90>
                <strong>symbol</strong>
            </td>
            <td class=rest_col width=90>
                <strong>encryption</strong>
            </td>
        </tr>
        <tr>
            <td class=&quot;pos_col&quot;>39.0&deg;e</td>
            <td class=rest_col>Hellas Sat 2</td>
            <td class=&quot;freq_col&quot;>12.606 H</td>
            <td class=rest_col>30000 - 2/3</td>
            <td class=enc_not_live>MPEG-4 BulCrypt</td>
        </tr>
    </table>',CAPTION, 'Arena Sport 4 (serbia) &nbsp;&ndash;&nbsp;19/10/14 - 11:30');" onmouseout="return nd();">
    Arena Sport 4 (serbia)
</a>

我需要将表格读入onmouseover事件。怎么读?

1 个答案:

答案 0 :(得分:0)

您可以使用HTML Agility Pack获取<a>标记的element属性,然后使用正则表达式获取字符串中的<table>,类似于以下代码:

var html = @"<a href='#' class='chan_live_not_free' onclick='return false;' onmouseover='return overlib(
                    <table>
                        <tr class=fieldRow>
                            <td class=posH_col width=40>
                                <strong>pos</strong>
                            </td>
                            <td class=rest_col width=90>
                                <strong>satellite</strong>
                            .
                            .
                            .

                        <tr>
                            <td class=&quot;pos_col&quot;>39.0&deg;e</td>
                            <td class=rest_col>Hellas Sat 2</td>
                            <td class=&quot;freq_col&quot;>12.606 H</td>
                            <td class=rest_col>30000 - 2/3</td>
                            <td class=enc_not_live>MPEG-4 BulCrypt</td>
                        </tr>
                    </table>,CAPTION, 'Arena Sport 4 (serbia) &nbsp;&ndash;&nbsp;19/10/14 - 11:30');' onmouseout='return nd();'>
                    Arena Sport 4 (serbia)
                </a>";

var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);

var value = doc.DocumentNode.SelectSingleNode("//a[@class='chan_live_not_free']").Attributes["onmouseover"].Value;

var text = Regex.Matches(value, @"<table>([^)]*)</table>")[0].Value;