我已经获取这个HTML的字符串```
现在就是要用正则获取我想要的天气的数据```
城市:深圳
日期:08年09月10日-11日 星期三
天气:晴
温度1:34
温度2:26
风力:≤3级
要获取3天天气信息已知字符穿里包含这样的信息:
<div class="City_Data">
<h3>今日 深圳</h3>
<p>08年09月10日-11日 星期三</p>
</div>
<div class="Weather_Icon_B"><img src="http://image2.sina.com.cn/dy/weather/images/figure/qing_big.gif" ></div>
<div class="Weather_TP">晴 34℃~26℃</div>
<div class="Weather_W"> 风力:≤3级</div><div class="City_Data">
<h3>明日 深圳</h3>
<p>08年09月11日-12日 星期四</p>
</div>
<div class="Weather_Icon_B"><img src="http://image2.sina.com.cn/dy/weather/images/figure/qing_big.gif" ><img src="http://image2.sina.com.cn/dy/weather/images/figure/duoyun_big.gif" ></div>
<div class="Weather_TP">晴转多云 35℃~27℃</div>
<div class="Weather_W"> 风力:≤3级</div>
<div class="City_Data">
<h3>后天 深圳</h3>
<p>08年09月12日-13日 星期五</p>
</div>
<div class="Weather_Icon_B"><img src="http://image2.sina.com.cn/dy/weather/images/figure/duoyun_big.gif" ></div>
<div class="Weather_TP">多云 35℃~27℃</div>
<div class="Weather_W"> 风力:≤3级</div>
请问如何写正则抓取数据```
谢谢了``
现在就是要用正则获取我想要的天气的数据```
城市:深圳
日期:08年09月10日-11日 星期三
天气:晴
温度1:34
温度2:26
风力:≤3级
要获取3天天气信息已知字符穿里包含这样的信息:
<div class="City_Data">
<h3>今日 深圳</h3>
<p>08年09月10日-11日 星期三</p>
</div>
<div class="Weather_Icon_B"><img src="http://image2.sina.com.cn/dy/weather/images/figure/qing_big.gif" ></div>
<div class="Weather_TP">晴 34℃~26℃</div>
<div class="Weather_W"> 风力:≤3级</div><div class="City_Data">
<h3>明日 深圳</h3>
<p>08年09月11日-12日 星期四</p>
</div>
<div class="Weather_Icon_B"><img src="http://image2.sina.com.cn/dy/weather/images/figure/qing_big.gif" ><img src="http://image2.sina.com.cn/dy/weather/images/figure/duoyun_big.gif" ></div>
<div class="Weather_TP">晴转多云 35℃~27℃</div>
<div class="Weather_W"> 风力:≤3级</div>
<div class="City_Data">
<h3>后天 深圳</h3>
<p>08年09月12日-13日 星期五</p>
</div>
<div class="Weather_Icon_B"><img src="http://image2.sina.com.cn/dy/weather/images/figure/duoyun_big.gif" ></div>
<div class="Weather_TP">多云 35℃~27℃</div>
<div class="Weather_W"> 风力:≤3级</div>
请问如何写正则抓取数据```
谢谢了``
string strText = @"<div class=""City_Data""><h3>今日 深圳 </h3><p>08年09月10日-11日 星期三 </p></div><div class=""Weather_Icon_B""> <img src=""http://image2.sina.com.cn/dy/weather/images/figure/qing_big.gif"" > </div><div class=""Weather_TP"">晴 34℃~26℃ </div><div class=""Weather_W""> 风力:≤3级 </div><div class=""City_Data""><h3>明日 深圳 </h3><p>08年09月11日-12日 星期四 </p></div><div class=""Weather_Icon_B""> <img src=""http://image2.sina.com.cn/dy/weather/images/figure/qing_big.gif"" > <img src=""http://image2.sina.com.cn/dy/weather/images/figure/duoyun_big.gif"" > </div><div class=""Weather_TP"">晴转多云 35℃~27℃ </div><div class=""Weather_W""> 风力:≤3级 </div><div class=""City_Data""><h3>后天 深圳 </h3><p>08年09月12日-13日 星期五 </p></div><div class=""Weather_Icon_B""> <img src=""http://image2.sina.com.cn/dy/weather/images/figure/duoyun_big.gif"" > </div><div class=""Weather_TP"">多云 35℃~27℃ </div><div class=""Weather_W""> 风力:≤3级 </div>";
Regex _regex = new Regex(@"<h3>(?<text01>[^<]*)[\s\S]*?<p>(?<DateTime>[^\&]*) (?<Day>[^\<]*)</p>[\S\s]*?<div class=.Weather_TP.>(?<weather>[^<]*)</div>[\s\S]*? (?<wind>[^<]*)</div>");
MatchCollection _matchCollection = _regex.Matches(strText); foreach (Match objMatch in _matchCollection)
{
Console.WriteLine(objMatch.Groups["text01"].Value + "—" + objMatch.Groups["DateTime"].Value + "—" + objMatch.Groups["Day"].Value + "—" + objMatch.Groups["weather"].Value + "—" + objMatch.Groups["wind"].Value);
}