2016-03-29 16 views
0

:Weatherzone'da sadece mevcut sıcaklık nasıl alınır ve gösterilir? C# kodu ile Weatherzone veri alınıyor

string url = "http://rss.weatherzone.com.au/?u=12994-1285&lt=twcid&lc=160255&obs=1&fc=1"; 
XmlReader reader = XmlReader.Create(url); 
SyndicationFeed feed = SyndicationFeed.Load(reader); 
reader.Close(); 

alın güncel hava:

var temperature = feed.Items.ToList()[0].Summary.Text.Trim(); 

Çıktı:

<b>Temperature:</b> 33.0&#176;C 
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/> 
<br /> 
<b>Feels like:</b> 38.0&#176;C<br /> 
<b>Dew point:</b> 23.0&#176;C 
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/> 
<br /> 
<b>Relative humidity:</b> 56%<br /> 
<b>Wind:</b> NE at 18 km/h, gusting to km/h 
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/> 
<br /> 
<b>Rain:</b> mm since 9am<br /> 
<b>Pressure:</b> 1013.0 hPa 
<img align="top" src="http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif" alt="steady"/> 
<br /> 

Soru: Bu çıktıda Sıcaklık alabilirim?

+0

sizin 'SyndicationFeed' nedir? Tam ad alanını sağlayabilir misiniz, lütfen? –

+0

Merhaba, System.ServiceModel.dll System.ServiceModel.Syndication kullanarak ekleyebilirsiniz –

cevap

0

Böyle bir şey ham yapabilirsiniz:

var stringTemp = "<b>Temperature:</b> 33.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Feels like:</b> 38.0&#176;C<br /> <b>Dew point:</b> 23.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Relative humidity:</b> 56%<br /> <b>Wind:</b> NE at 18 km/h, gusting to km/h <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Rain:</b> mm since 9am<br /> <b>Pressure:</b> 1013.0 hPa <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br />"; 
var start = stringTemp.IndexOf("</b>"); 
var end = stringTemp.IndexOf("<img"); 
var temp = stringTemp.Substring(start + "</b>".Length, end - start - "<img".Length); 
0

bir başka yolu

var temperature = "<b>Temperature:</b> 33.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Feels like:</b> 38.0&#176;C<br /> <b>Dew point:</b> 23.0&#176;C <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Relative humidity:</b> 56%<br /> <b>Wind:</b> NE at 18 km/h, gusting to km/h <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br /> <b>Rain:</b> mm since 9am<br /> <b>Pressure:</b> 1013.0 hPa <img align=\"top\" src=\"http://www.weatherzone.com.au/images/widgets/nav_trend_steady.gif\" alt=\"steady\"/> <br />"; 

C#:

private static string Temperature(string temperature) 
    { 
     try 
     { 
      string[] value = Regex.Split(temperature, "\n"); 
      string[] temp = Regex.Split(value[0], "</b> "); 
      return temp[1].Substring(0, 2); 
     } 
     catch { return string.Empty; } 
    }