网页中部分代码如下:
---------------------------------------------------
<div class="item">
    <div class="pic">
        <a target="_blank" href="http://item.taobao.com/item.htm?id=8121200640">
        <img src="http://img01.taobaocdn.com/bao/uploaded/i1/T1AcdRXdxfXXbSw1U._082124.jpg_160x160.jpg">
        </a>
    </div>
    <div class="desc">
    <a target="_blank" href="http://item.taobao.com/item.htm?id=8121200640" class="permalink"> 促销包邮经典实拍                       </a>
    </div>
    <div class="price">
         <span>一口价</span>
         <strong>198.0元</strong>
    </div>
</div>
------------------------------------------------------------
求:
   图片地址
   相应文字描述
   价格
------------
昨天求了一次,得到高人相助,交上去后说不行,还要加个价格

解决方案 »

  1.   

            string pstr = @"(?is)<div class=""pic"">.*?<img src=""([^""]*).*?<div class=""desc"">\s*<a[^>]*>([^<]*).*?<div class=""price"">.*?<strong>(\d+(?:\.\d+)?)元";
            Match m = Regex.Match(str, pstr);
            m.Groups[1].Value; //或m.Result("$1");
            m.Groups[2].Value; //或m.Result("$2");
            m.Groups[3].Value; //或m.Result("$3");
      

  2.   

    这样只能取一个,当一个网页中有很多个这样的Div时,就没有效果了!
      

  3.   

    1楼的只是匹配一次
    你如果想要匹配多次
    就用foreach不就OK了 foreach(Match m in Regex.Matches(str, pstr))
    {
            m.Groups[1].Value; //或m.Result("$1");
            m.Groups[2].Value; //或m.Result("$2");
            m.Groups[3].Value; //或m.Result("$3");
    }
      

  4.   

    明天你的经理又想让你加个数量什么的,你又应该怎么办?
    抽时间看看这个
    http://download.csdn.net/source/2844387
      

  5.   

            string temp = @"<div class=""item"">
                      <div class=""pic"">
                      <a target=""_blank"" href=""http://item.taobao.com/item.htm?id=8121200640"">
                      <img src=""http://img01.taobaocdn.com/bao/uploaded/i1/T1AcdRXdxfXXbSw1U._082124.jpg_160x160.jpg"">
                      </a>
                      </div>
                      <div class=""desc"">
                      <a target=""_blank"" href=""http://item.taobao.com/item.htm?id=8121200640"" class=""permalink""> 促销包邮经典实拍 </a>
                      </div>
                      <div class=""price"">
                      <span>一口价</span>
                      <strong>198.0元</strong>
                      </div>
                    </div>";        MatchCollection mc = Regex.Matches(temp, @"(?i)<div class=\""item(?:[^>]*>){3}\s+<img[^>]+?src=\""([^\""]+)\""(?:[^>]*>){5}([^<>]+)(?:[^>]*>){6}([^<>]+)");
            foreach (Match m in mc)
            {
                Console.WriteLine(m.Groups[1]);
                Console.WriteLine(m.Groups[2]);
                Console.WriteLine(m.Groups[3]);
            }
      

  6.   

    (?is)<img\s.*?src=(['"]?)(?<url>[^'" ]+)(?=\1)[^>]*>[^>]*>([^>]*>){3}\s*([^<]+)(?:[^>]*>){6}(\d+(?:\.\d+)?)
    在昨天基础上。修改一点就好,倒数第二个,也就是分组4就是你要的,其他的不变。
      

  7.   

        public static void Test()
        {
            string html = @"<div class=""item"">
      <div class=""pic"">
      <a target=""_blank"" href=""http://item.taobao.com/item.htm?id=8121200640"">
      <img src=""http://img01.taobaocdn.com/bao/uploaded/i1/T1AcdRXdxfXXbSw1U._082124.jpg_160x160.jpg"">
      </a>
      </div>
      <div class=""desc"">
      <a target=""_blank"" href=""http://item.taobao.com/item.htm?id=8121200640"" class=""permalink""> 促销包邮经典实拍 </a>
      </div>
      <div class=""price"">
      <span>一口价</span>
      <strong>198.0元</strong>
      </div>
    </div>";
            MatchCollection mc = Regex.Matches(html, @"(?is)<img\s.*?src=(['""]?)(?<url>[^'"" ]+)(?=\1)[^>]*>[^>]*>([^>]*>){3}\s*([^<]+)(?:[^>]*>){6}(\d+(?:\.\d+)?)");
            foreach (Match m in mc)
            {
                Console.WriteLine(m.Groups[3].Value);//说明
                Console.WriteLine(m.Groups[4].Value);//价格
                Console.WriteLine(m.Groups[5].Value);//图片地址
            }
        }
      

  8.   


            private void button1_Click(object sender, EventArgs e)
            {
                string url = "http://shop62898199.taobao.com/?search=y";
                string result = null;
                WebClient client = new WebClient();
                result = client.DownloadString(url);
               
               Test(result)
             }
        public void Test(string html)
            {             
                string str = null;
            
                MatchCollection mc = Regex.Matches(html, @"(?is)<img\s.*?src=(['""]?)(?<url>[^'"" ]+)(?=\1)[^>]*>[^>]*>([^>]*>){3}\s*([^<]+)(?:[^>]*>){6}(\d+(?:\.\d+)?)");
                foreach (Match m in mc)
                {
                    //Console.WriteLine(m.Groups[3].Value);//说明
                    //Console.WriteLine(m.Groups[4].Value);//价格
                    //Console.WriteLine(m.Groups[5].Value);//图片地址
                    str += m.Groups[3].Value + m.Groups[4].Value + m.Groups[5].Value + "\n";
                }
                richTextBox1.Text = str;
                
            }
    ---------------------------------------------------------------
    程序崩馈了