日期:2014-05-17 浏览次数:20884 次
class Program { static string url = "http://trend.baidu.lehecai.com/ssqZst!ssqjbzs.jhtml?flag=jbzs"; static void Main(string[] args) { WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; string s = wc.DownloadString(url); //Console.Write(s); //<td style="background-color: #FEFFEF;" class="chartBall01 ">06</td> //<td style="background-color: #EEF5FD;" class="chartBall02 ">01</td> s = s.Replace("\r", " ").Replace("\n", " "); MatchCollection matches = Regex.Matches(s, "<td(.*?)class=\"chartBall01 \"(.*?)>(\\d+)</td>", RegexOptions.IgnoreCase | RegexOptions.Multiline); List<string> list = new List<string>(); for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; Console.WriteLine(match.Value); } Console.ReadKey(); } }
MatchCollection matches = Regex.Matches(s, "<td([^>]*?)class=\"chartBall01 \"(.*?)>(\\d+)</td>", RegexOptions.IgnoreCase | RegexOptions.Multiline);