ASP.NET 일기 예보
using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.html controls;
using system.data.sqlclient;
using system.net;
using system.io;
using system.collections;
///lt; 요약 gt;
/// Weather 에 대한 요약 설명
///lt; /요약 gt;
public class weather
{
public weather ()
P >
}
public static string convertcodebycity (stringcity)
{
스위치 (시)
{
case "베이징":
case
break;
default:
break;
}
복귀 코드;
}
public static ArrayList getweather (string code)
{; 소나기' 스트링
[2] "9℃" 스트링
[3] "29℃" 스트링
try
{
http webrequest request = (http webrequest) webrequest
Create ("/iframe/weather/"+code+"_ w.html");
request.method = "get";
//request.timeout = 1;
request.contenttype = "application/x-www-form-urlencoded";
webresponseresponse = request.getresponse ();
streams = response.getresponsestream ();
streamreader Sr = new streamreader (s, system.text.encoding.getencoding ("gb2312)
html = sr.read to end ();
s.close ();
sr.close ();
}
catch (exception err)
{
throw new ew
}
intcount = html.length;
intstarindex = html.indexof ("lt; Table ",0, count);
int end index = html.index of ("lt; /tablegt; " , 스타인덱스, count-star starIndex);
html = html.substring (starindex, end index-starindex+8);
// 구/군/시 가져오기
int city startindex = html.index of ("lt; Bgt;; " , 0, html.length);
intcity end index = html.index of ("lt; /bgt; " , 0, html.length);
stringcity = html.substring (city startindex+3, city end index-city startindex-3)
// 날씨 얻기
int weather startindex = html.index of ("lt; Bgt;; " , city end index);
intweather end index = html.index of ("lt; /bgt; " , weather startindex);
s
Tringweather = html.substring (weather startindex+3, weather end index-weather startindex-3);
// 온도 획득
int temperature startindex = html.index of ("lt; B ",weather end index);
inttemperature end index = html.indexof ("lt; /bgt; " , weather end index+3);
stringtemperature = html.substring (temperature startindex+21, temperature end index-temperature
intint1 = temperature.indexof ("℃", 0);
intint2 = temperature.indexof ("~", 0);
intint3 = temperature.indexof ("℃", int2);
stringmin temperature = temperature.substring (int2+1, int3-int2);
stringmax temperature = temperature.substring (0, int2-int1+2);
// 바람 얻기
int wind force startindex = html.index of ("바람:", temperatureEndIndex);
int wind force end index = html.index of ("lt; Brgt;; " , windforce startindex);
stringwindforce = html.substring (windforce startindex+3, windforce end index-windforce ss
if (Windforce.Contains ("미만") amp;; Amp;; (! Windforce.Contains ("같음"))//풍력에 "보다 작음" 또는 "보다 작거나 같음" 이라는 단어가 포함되어 있는지 확인하고 있는 경우 2-
{로 바꿉니다
stringstr windforce = windforce.substring (2, windforce.length-3);
intmin windforce = int32.pars
E (e(strWindforce)-1;;
windforce = windforce.replace ("보다 작음", minwindforce.tostring ()+"-");
}
elseif (windforce.contains ("작거나 같음"))
{<
int min wind force = int32.parse (str wind force)-1;
windforce = windforce.replace ("작거나 같음", minwindforce.tostring ()+"-");
}
arraylistal = new ArrayList ();
al.add (city);
al.add (weather);
al.add (min temperature);
al.add (최대 템플릿);
al.add (windforce);
returnal;
}
}