1、分别得到h2标签中间的值,a标签的href值,下面两个p标签中间的值。string id="2342342";
string href=@"/index.php?option=com_show&did[]=2342342&layout=details";
string name1="士大夫认为";
string name2="哥士大夫";
下面是部分HTML文件:<ul class="cookingshow_list fn-clear">
      <li>
        <h2 class="number">2342342</h2>
        <a href="/index.php?option=com_show&amp;did[]=2342342&amp;layout=details"><img alt="" src="/images/thumb/1234.jpg" width="103" height= "103"><span class="pngFix"></span></a>
        <p>士大夫认为</p>
        <p class="name">哥士大夫</p>
      </li>
        <li>
        <h2 class="number">235278</h2>
        <a href="/index.php?option=com_show&amp;did[]=235278&amp;layout=details"><img alt="" src="/images/thumb/7453.jpg" width="103" height= "103"><span class="pngFix"></span></a>
        <p>胜多负少</p>
        <p class="name">随风倒</p>
      </li>
</ul>2、分别得到3个votes的值:int votes1=72;
int votes2=70;
int votes3=69;
下面是部分HTML文件:<div class="step_btn_num fn-clear">
               <span id="votes1">72</span>
      <input type="hidden" name="votecat" id="votecat" value="歌唱的"> 
            <span id="votes2">70</span>
      <input type="hidden" name="votecat" id="votecat" value="了仓库"> 
            <span id="votes3">69</span>
      <input type="hidden" name="votecat" id="votecat" value="了从恶"> 
</div>
感激不及。

解决方案 »

  1.   

    第一个            StreamReader reader = new StreamReader("c:\\temp\\1.txt",Encoding.Default);
                string source = reader.ReadToEnd();
                Regex reg = new Regex(@"(?<=<h2[^<>]*?>).*?(?=</h2>)");
                MatchCollection mc = reg.Matches(source);
                foreach (Match m in mc)
                {
                    MessageBox.Show(m.Value);
                }第二个            StreamReader reader = new StreamReader("c:\\temp\\1.txt",Encoding.Default);
                string source = reader.ReadToEnd();
                Regex reg = new Regex(@"(?<=<span id=""votes[\d]+"">).*?(?=</span>)");
                MatchCollection mc = reg.Matches(source);
                foreach (Match m in mc)
                {
                    MessageBox.Show(m.Value);
                }
      

  2.   

    第一个
     string source="html源码"; 
      Regex Reg = new Regex(@"(?is)(?<=<P>).*?(?=</P>)", RegexOptions.IgnoreCase);   string Content = Reg.Match(source).Value;  
     Content = Regex.Replace(Content, @"(?i)(|&nbsp;)", "", RegexOptions.IgnoreCase);
      

  3.   

    2、
    string s = "<a target=\"_blank\" href=\"show.asp?id=193972\">出售深红色玩具泰迪熊宝宝</a>";
                Regex regex = new Regex("<a(?:\\s+.+?)*?\\s+href=\"([^\"]*?)\".*?>(.*?)</a>");
                Match m = regex.Match(s);
                Console.WriteLine("{0}\nhref: {1}\n链接文字: {2}", s, m.Groups[1].Value, m.Groups[2].Value);