日期:2014-05-17  浏览次数:20891 次

求一正则取出Html里的值

<div class="kqkj_l" id="kj_content">
    <div class="qh_kj_h">
          <div class="qs_kj_nane">江西11选5第2014022341期开奖结果</div>
    </div>
    <div class="dqkj_bqxl">
        <div class="dqkj_time"  style="font-size:10pt;">开奖时间:2014-02-23 15:50:00</div>
        <div class="ljtz_btn"><input type="button" value="立即投注" onclick="go_tz();"/></div>
    </div>
    <div class="dqkj_kjhm">
        <div class="kjhm">开奖号码:</div>
        <div class="hq_bg">08</div>
        <div class="hq_bg">01</div>
        <div class="hq_bg">11</div>
        <div class="hq_bg">02</div>
        <div class="hq_bg">07</div>
    </div>
</div>


取出
开奖时间:2014-02-23 15:50:00
开奖号码:08,01,11,02,07
开奖期号:2014022341

------解决方案--------------------
string sInput = File.ReadAllText(@"C:\Users\myx\Desktop\Test.txt", Encoding.GetEncoding("GB2312"));
            string pattern = @"<div[^>]*?id=(['""]?)kj_content\1[^>]*?>[\s\S]*?<div[^>]*?class=(['""]?)qs_kj_nane\2[^>]*?>[^<>]*?(?<date>\d+)期[^<>]*?</div>[\s\S]*?<div[^>]*?class=(['""]?)dqkj_time\3[^>]*?>(?<time>[^>]*?)</div>[\s\S]*?<div[^>]*?class=(['""]?)dqkj_kjhm\4[^>]*?>[\s\S]*?(<div[^>]*?class=""hq_bg""\s*?>(?<code>\d+)</div>\s*?)+</div>";
            Match m = Regex.Match(sInput, pattern);
            string date = m.Groups["date"].Value;//2014022341
            string time = m.Groups["time"].Value;//开奖时间:2014-02-23 15:50:00
            string coed = string.Join(",", m.Groups["code"].Captures.Cast<Capture>().Select(a => a.Value));//08,01,11,02,07

------解决方案--------------------

  public static string ClearHTMLTags(string HTML)
        {
            string[] Regexs ={
                        @"<script[^>]*?>.*?</script>",
                        @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]
------解决方案--------------------
[^\7])*?\7
------解决方案--------------------
\w+)
------解