productListing">
  <tr>
    <td align="left" class="productListing-data"><a style="font-size:8pt" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4369.html?osCsid=2e69ba852cd807339d1117e15739f428"><img src="images/watches-25082011-098-rm-.jpg" border="0" alt="DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch" title=" DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch " width="180" height="223.0985915493"></a><br><a style="" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4369.html?osCsid=2e69ba852cd807339d1117e15739f428"><p class="prod_name_listing">DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch</p></a><br>这只是代码中的一部分 但是其他的格式都是一样的 从这样的代码中获取
XX.html
比如http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4369.html(?osCsid=2e69ba852cd807339d1117e15739f428)括号里面的可要可不要大家可以看到这段代码有两个相同的这样的链接 只需要取一个就行了 拜求大神帮忙

解决方案 »

  1.   

                string str = File.ReadAllText(@"E:\1.txt", Encoding.GetEncoding("gb2312"));
                Regex reg = new Regex(@"(?is)(?<=<td[^>]*?class=""productListing-data""[^>]*?>\s*)<a[^>]*?href=""([^""]+)""[^>]*?>");
                foreach (Match m in reg.Matches(str))
                    Console.WriteLine(m.Groups[1].Value);
      

  2.   

    我的怎么没得到数据 我的是vs2008 c#winform中 大神
    奇怪
      

  3.   


    是不是,你这里面的那个href=""([^""]+)忘了加非贪婪了。
    改成:@"(?is)(?<=<td[^>]*?class=""productListing-data""[^>]*?>\s*)<a[^>]*?href=""([^""]+?)""[^>]*?>"
    试试
      

  4.   

    得到两个的话,自己hash一个吧!(?<=href=\")[^\"]*(?=\")
      

  5.   


    <table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListing">
      <tr>
        <td align="left" class="productListing-data"><a style="font-size:8pt" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4369.html"><img src="images/watches-25082011-098-rm-.jpg" border="0" alt="DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch" title=" DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch " width="180" height="223.0985915493"></a><br><a style="" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4369.html"><p class="prod_name_listing">DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch</p></a><br>
      
    <span style="text-align:center; color:000000; text-decoration:none; font-size:10pt; font-weight:bold">Price: $599</span></a>
    <div style="height:12px"></div>
     
    </td>
        <td align="left" class="productListing-data"><a style="font-size:8pt" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4368.html"><img src="images/watches-25082011-086-rm-.jpg" border="0" alt="DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch" title=" DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch " width="180" height="223.0985915493"></a><br><a style="" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4368.html"><p class="prod_name_listing">DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch</p></a><br>
      
    <span style="text-align:center; color:000000; text-decoration:none; font-size:10pt; font-weight:bold">Price: $599</span></a>
    <div style="height:12px"></div>
    </td> <td align="left" class="productListing-data"><a style="font-size:8pt" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4367.html"><img src="images/watches-25082011-074-rm-.jpg" border="0" alt="DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch" title=" DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch " width="180" height="223.0985915493"></a><br><a style="" href="http://www.replicamaster.com/datejast-rolex-36mm-silver-jubilee-bracelet-swiss-watch-p-4367.html"><p class="prod_name_listing">DateJast Rolex 36mm Silver Jubilee Bracelet Swiss Watch</p></a><br>
      
    <span style="text-align:center; color:000000; text-decoration:none; font-size:10pt; font-weight:bold">Price: $599</span></a>
    <div style="height:12px"></div>
     </td>
     </tr>
    </table>
    代码差不多就是这样的
    大神再看看
      

  6.   

    To soonfei 大神还是不行
    To pmars 大神我对正则不熟习
      

  7.   

    循环一次就break; StreamReader sr = new StreamReader(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));
                string tempStr = sr.ReadToEnd();
                string pattern = @"(?im)(?<=(productListing-data[^>]*>))<a[^>]+href=""([^""]+)""[^>]*>";
                //tempStr = Regex.Replace(tempStr,pattern,"$2");
                MatchCollection mc = Regex.Matches(tempStr, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                foreach (Match m in mc)
                {
                    //循环输出
                    string url = m.Groups[2].Value;//输出:
                    //string href = m.Groups["href"].Value;//链接地址
                    //string text = m.Groups["text"].Value.Substring(href.Length-1); ;//链接内容            }
      

  8.   

    string str = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\test.txt") ;        Regex reg = new Regex(@"(?is)<a[^>]+?href=""(.+?)""[\s\S]*?>");        foreach (Match m in reg.Matches(str))
            {
                Response.Write(m.Groups[1].Value + "<br/>");
            }有重复,行不?
      

  9.   

    再请教各位大神一个问题 最后一个问题<br>This is a <font color="#000000"><b></b></font> Watch<br><font color="#000000"><b>Movement:</b></font> 7750 Valjoux Swiss Made Top Grade<br><font color="#000000"><b>Functions:</b></font> Hours, Minutes, Seconds, Stopwatch<br><font color="#000000"><b>Dial:</b></font> Black Dial<br><font color="#000000"><b>Case:</b></font> Solid 440 Stainless Steel, Swiss Made High Grade One Piece Forged Case<br><font color="#000000"><b>Bezel:</b></font> PVD coating solid 440 Stainless Steel Bezel<br><font color="#000000"><b>Hands:</b></font> Black Hands<br><font color="#000000"><b>Numerals:</b></font> Shaped Numerals<br><font color="#000000"><b>Back:</b></font> Screw, See Through<br><font color="#000000"><b>Crown:</b></font> 3 Crowns, One-Piece Solid Screw-Down Winding Crown and 2 Crowns to control the Chronographs<br><font color="#000000"><b>Crystal:</b></font> High Grade Sapphire Crystal Scratch-Proof Laser Etched Crown at 6 o&#039;clock<br><font color="#000000"><b>Bracelet (Strap):</b></font> Steel Oyster with Oysterlock Safety Clasp and Easylink Comfort Extension Link<br><font color="#000000"><b>Markings:</b></font> Exact Weight, 100% Correct Markings, Engravings and Serials<br><font color="#000000"><b>Water Proof:</b></font> Water Resistant and Water Proof 3ATM / 30 Meters<br><font color="#000000"><b>Guarantee:</b></font> 10 Days Unconditional Guarantee, 6 months Warranty <small>(<a href="http://www.replicamaster.com/information.php?info_id=14">read more</a>)</small><br><font color="#000000"><b>Shipping:</b></font> FREE Worldwide<br>
    <br><Br>
    <br>The pictures you see were taken by the <b>ReplicaMaster.com</b> team using the 
    <b>actual replica watch</b>, what you see here is exactly what we ship.从这段代码中获取
    比如XX:XXX 取出 XX XXX
    就像代码中的<br>This is a <font color="#000000"><b></b></font> Watch<br><font color="#000000"><b>Movement:</b></font> 7750 Valjoux Swiss Made Top Grade<br><font color="#000000"><b>Functions:........取出Movement和7750 Valjoux Swiss Made Top Grade 
      

  10.   


         string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));
                string pattern = @"(?im)(?<=(<br/?><font[^>]+><b>([^:]+):\s*</b>)</font>\s*)([^<]+)<br/?>";
                //tempStr = Regex.Replace(tempStr,pattern,"$2");
                MatchCollection mc = Regex.Matches(tempStr, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                foreach (Match m in mc)
                {
                    //循环输出
                    string title = m.Groups[2].Value;//输出:Movement
                    string text = m.Groups[3].Value;//输出:7750 Valjoux Swiss Made Top Grade 
                    //string href = m.Groups["href"].Value;//链接地址
                    //string text = m.Groups["text"].Value.Substring(href.Length-1); ;//链接内容            }