如题,想把http://www.tianqiyubao.net/city/58457.htm这个网页中间的6个天气内容取出来,即从“<div id="weather">”这个节点开始的数据
希望能按date,description,temperature,wind 存成一个有6条记录的数组或MatchCollection
希望哪位高手能帮忙,谢谢!

解决方案 »

  1.   

    try...MatchCollection mc = Regex.Matches(yourStr, @"<div\s*class=""item"">\s*<div\s*class=""date"">(?<date>[^<]*(?:\(\<span[^>]*>)?[^>]*(?:</span>\))?)\s*</div>\s*<div(?:(?!</?div\b).)*</div>\s*<div\s*class=""description"">(?<description>[^<]*)</div>\s*<div\s*class=""temperature"">(?<temperature>[^<]*)</div>\s*<div\s*class=""wind"">(?<wind>[^<]*)</div>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
    foreach (Match m in mc)
    {
        richTextBox2.Text += Regex.Replace(m.Groups["date"].Value, @"<[^>]*>", "") + "\n";
        richTextBox2.Text += m.Groups["description"].Value + "\n";
        richTextBox2.Text += m.Groups["temperature"].Value + "\n";
        richTextBox2.Text += m.Groups["wind"].Value + "\n\n";
    }