从<div id="productDescription" class="productGeneral biggerText"><h3>Description:</h3>
<p>2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!</p>
<h3>Features:</h3>
<ul>
<li>Color:As picture</li>
<li>Size: W32 cm X H29 cm X D17 cm</li>
</ul>
<h3>Details:</h3>
<ul>
<li>Side laces to change the shape of the bag</li>
<li>Red textile linning</li>
<li>Leather trimmings</li>
<li>Large interior zipped pocket which can fit a long wallet</li>
<li>Interior D-ring for keys and an accessory<li>
<li>Metallic pieces in shiny golden brass</li>
</ul></div>
这段代码中 获取
2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get one in our online store!As pictureW32 cm X H29 cm X D17 cmSide laces to change the shape of the bagRed textile linning
Leather trimmings
Large interior zipped pocket which can fit a long wallet
Interior D-ring for keys and an accessory
Metallic pieces in shiny golden brass跪求大神帮忙

解决方案 »

  1.   


                // html 就是输入字符串
                StringBuilder sb = new StringBuilder();
                foreach(Match m in Regex.Matches(html, @"<([^>]+)>([^<]*)</[^>]+>")) {
                    if(m.Groups[1].Value == "p") {
                        sb.Append(m.Groups[2].Value);
                        sb.Append('\n');
                    } else if(m.Groups[1].Value == "li") {
                        string value = m.Groups[2].Value;
                        int idx = value.IndexOf(':');
                        if(idx != -1) value = value.Substring(idx + 1);
                        sb.Append(value);
                        sb.Append('\n');
                    }
                }
                Console.WriteLine(sb);
      

  2.   


    StreamReader sr = new StreamReader(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));
                string tempStr =sr.ReadToEnd();
                string pattern = @"<(li|p)[^>]*>([^<]+:)*([^<]+)</(li|p)>";
                MatchCollection mc = Regex.Matches(tempStr, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                foreach (Match m in mc)
                {
                    string tempValue = m.Value;
                    string text = m.Groups[3].Value;//循环输出内容
                }
      

  3.   


    void Main()
    {
      string str = @"<div id=""productDescription"" class=""productGeneral biggerText""><h3>Description:</h3>
    <p>2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get  one in our online store!</p>
    <h3>Features:</h3>
    <ul>
    <li>Color:As picture</li>
    <li>Size: W32 cm X H29 cm X D17 cm</li>
    </ul>
    <h3>Details:</h3>
    <ul>
    <li>Side laces to change the shape of the bag</li>
    <li>Red textile linning</li>
    <li>Leather trimmings</li>
    <li>Large interior zipped pocket which can fit a long wallet</li>
    <li>Interior D-ring for keys and an accessory<li>
    <li>Metallic pieces in shiny golden brass</li>
    </ul></div>";
      foreach(Match m in Regex.Matches(str,@"(?is)(?<=<(p|li)>).*?(?=</?\1>)"))
      {
       Console.WriteLine((m.Value.Contains("Color:")||m.Value.Contains("Size:"))?m.Value.Split(':')[1]:m.Value);
      }
      
      /*
    2010 New LV Monogram Canvas Neverfull MM M98789 is a designer bag, if you like it, you could get  one in our online store!
    As picture
     W32 cm X H29 cm X D17 cm
    Side laces to change the shape of the bag
    Red textile linning
    Leather trimmings
    Large interior zipped pocket which can fit a long wallet
    Interior D-ring for keys and an accessory
    Metallic pieces in shiny golden brass   */
    }
      

  4.   

    还有一个小问题
    eof Main Product Image--><!--bof Product Name--><h1 id="productName" class="productGeneral">Louis Vuitton Monogram Canvas Delightful PM MM M40352</h1><!--eof Product Name--><div id="stylebags_pro_model">Model: M40352</div><!--bof Product Price block --><h2 id="productPrices" class="productGeneral"><span class="normalprice">$299.00 </span>&nbsp;<span class="productSpecialPrice">$209.00</span></h2><!--
    这当中获取
    Louis Vuitton Monogram Canvas Delightful PM MM M40352M40352$209.00
    最后一个问题了 拜托大神了
      

  5.   

    string test="<h1 id=\"productName\" class=\"productGeneral\">Louis Vuitton Monogram Canvas Delightful PM MM M40352</h1><!--eof Product Name--><div id=\"stylebags_pro_model\">Model: M40352</div><!--bof Product Price block --><h2 id=\"productPrices\" class=\"productGeneral\"><span class=\"normalprice\">$299.00 </span>&nbsp;<span class=\"productSpecialPrice\">$209.00</span></h2>";
        Regex re = new Regex("<h1 id=\"productName\" class=\"productGeneral\">([^<]*)</h1>.*Model:([^<]*)</div>.*<span class=\"productSpecialPrice\">([^<]*)</span>");
        foreach (Match s in re.Matches(test))
        {
            Console.WriteLine(s.Groups[1].Value.ToString().Trim());
            Console.WriteLine(s.Groups[2].Value.ToString().Trim());
            Console.WriteLine(s.Groups[3].Value.ToString().Trim());
        }
      

  6.   

     string str = "<h1 id=\"productName\" class=\"productGeneral\">Louis Vuitton Monogram Canvas Delightful PM MM M40352</h1><!--eof Product Name--><div id=\"stylebags_pro_model\">Model: M40352</div><!--bof Product Price block --><h2 id=\"productPrices\" class=\"productGeneral\"><span class=\"normalprice\">$299.00 </span>&nbsp;<span class=\"productSpecialPrice\">$209.00</span></h2>";        Regex reg = new Regex(@"(?is)<(h1|div|span)[^>]*?>(?:[^::]+?[::])?(.+?)</\1>");        foreach (Match m in reg.Matches(str))
            {
                Response.Write(m.Groups[2].Value+"<br/>");
            }
    /*
    Louis Vuitton Monogram Canvas Delightful PM MM M40352
    M40352
    $299.00
    $209.00
    */
      

  7.   


                Regex reg = new Regex(@"(?i)<h1\s*?id=.productName[^>]*?>([^<]*?)</h1>[^;]*?;<span\s*?class=.productSpecialPrice[^>]*?>([^<]*?)</span>");            MatchCollection mc = reg.Matches(test);
                String[] number = null;
                foreach (Match m in mc)
                {
                    number = m.Groups[1].Value.Split(' ');
                    Console.WriteLine(m.Groups[1].Value);
                    Console.WriteLine(number[number.Length-1]);
                    Console.WriteLine(m.Groups[2].Value);
                }/*输出
    Louis Vuitton Monogram Canvas Delightful PM MM M40352
    M40352
    $209.00*/
      

  8.   


     StreamReader sr = new StreamReader(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));
                string tempStr =sr.ReadToEnd();
                string pattern = @"(?m)(?<=<(h1|div|span)[^>]*>)([^<]+:)*([^<]+)(?=</?\1>)";
                MatchCollection mc = Regex.Matches(tempStr, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                foreach (Match m in mc)
                {
                    if (!string.IsNullOrEmpty(m.Groups[3].Value))
                    {
                        //循环输出内容
                        Console.WriteLine(m.Groups[3].Value);
                    }
                }
      

  9.   

    分太少了
    请各位大神 来这里
    http://topic.csdn.net/u/20111101/13/7958f503-ec6c-43b4-857a-a62e81039ad7.html
    继续接分