剛趕工寫了一個獲取新浪天氣預報的功能
<iframe frameborder=
涉及的核心代碼如下
Code
public static ArrayList GetWeather(string code)
{
/*
[
[
[
[
[
*/
string html =
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest
request
//request
request
WebResponse response = request
Stream s = response
StreamReader sr = new StreamReader(s
html = sr
s
sr
}
catch (Exception err)
{
throw new Exception(
}
int count = html
int starIndex = html
int endIndex = html
html = html
//得到城市
int cityStartIndex = html
int cityEndIndex = html
string City = html
//得到天氣
int weatherStartIndex = html
int weatherEndIndex = html
string Weather = html
//得到溫度
int temperatureStartIndex = html
int temperatureEndIndex = html
string Temperature = html
int int
int int
int int
string MinTemperature = Temperature
string MaxTemperature = Temperature
//得到風力
int windforceStartIndex = html
int windforceEndIndex = html
string Windforce = html
if (Windforce
{
//Windforce = Windforce
string strWindforce = Windforce
int minWindforce = Int
Windforce = Windforce
}
else if (Windforce
{
string strWindforce = Windforce
int minWindforce = Int
Windforce = Windforce
}
ArrayList al = new ArrayList();
al
al
al
al
al
return al;
}
這裡涉及到一個ConvertCode類
代碼如下
Code
using System;
using System
using System
namespace WebApplication
{
public class ConvertCode
{
public static string ConvertCodeByCity(string City)
{
string Code =
switch (City)
{
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
case
Code =
break;
default:
break;
}
return Code;
}
}
}
核心代碼如下
Code
public static ArrayList GetThreeDayWeather(string City)
{
ArrayList al = new ArrayList();
/*
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
*/
string Html =
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = string
byte[] data = encoding
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest
request
request
WebResponse response = request
Stream s = response
StreamReader sr = new StreamReader(s
Html = sr
s
sr
}
catch (Exception err)
{
throw new Exception(
}
//去除多余代碼
int count = Html
int starIndex = Html
int endIndex = Html
Html = Html
try
{
#region 得到今天的天氣
//得到今天的標識跟城市
int firstDayAndCityStartIndex = Html
int firstDayAndCityEndIndex = Html
string FirstDayAndCity = Html
//得到今天的日期跟星期
int firstDateStartIndex = Html
int firstDateEndIndex = Html
string FirstDate = Html
//得到今天的天氣
int firstWeatherStartIndex = Html
int firstWeatherEndIndex = Html
string FirstWeather = Html
//得到今天的溫度
int firstTemperatureStartIndex = firstWeatherEndIndex +
int firstTemperatureEndIndex = Html
string FirstTemperature = Html
int int
int int
int int
string FirstMinTemperature = FirstTemperature
string FirstMaxTemperature = FirstTemperature
//得到今天的風力
int firstWindforceStartIndex = Html
int firstWindforceEndIndex = Html
string FirstWindforce = Html
if (FirstWindforce
{
}
else if (FirstWindforce
{
string strWindforce = FirstWindforce
int minWindforce = Int
FirstWindforce = FirstWindforce
}
else if (FirstWindforce
{
string strWindforce = FirstWindforce
int minWindforce = Int
FirstWindforce = FirstWindforce
}
#endregion
#region 得到明天的天氣
//得到明天的標識跟城市
int secondDayAndCityStartIndex = Html
int secondDayAndCityEndIndex = Html
string secondDayAndCity = Html
//得到明天的日期跟星期
int secondDateStartIndex = Html
int secondDateEndIndex = Html
string SecondDate = Html
//得到明天的天氣
int secondWeatherStartIndex = Html
int secondWeatherEndIndex = Html
string SecondWeather = Html
//得到明天的溫度
int secondTemperatureStartIndex = secondWeatherEndIndex +
int secondTemperatureEndIndex = Html
string SecondTemperature = Html
int int
int int
int int
string SecondMinTemperature = SecondTemperature
string SecondMaxTemperature = SecondTemperature
//得到明天的風力
int secondWindforceStartIndex = Html
int secondWindforceEndIndex = Html
string SecondWindforce = Html
if (SecondWindforce
{
}
else if (SecondWindforce
{
string strWindforce = SecondWindforce
int minWindforce = Int
SecondWindforce = SecondWindforce
}
else if (SecondWindforce
{
string strWindforce = SecondWindforce
int minWindforce = Int
SecondWindforce = SecondWindforce
}
#endregion
#region 得到後天的天氣
//得到後天的標識跟城市
int thirdDayAndCityStartIndex = Html
int thirdDayAndCityEndIndex = Html
string thirdDayAndCity = Html
//得到後天的日期跟星期
int thirdDateStartIndex = Html
int thirdDateEndIndex = Html
string ThirdDate = Html
//得到後天的天氣
int thirdWeatherStartIndex = Html
int thirdWeatherEndIndex = Html
string ThirdWeather = Html
//得到後天的溫度
int thirdTemperatureStartIndex = thirdWeatherEndIndex +
int thirdTemperatureEndIndex = Html
string ThirdTemperature = Html
int int
int int
int int
string ThirdMinTemperature = ThirdTemperature
string ThirdMaxTemperature = ThirdTemperature
//得到後天的風力
int thirdWindforceStartIndex = Html
int thirdWindforceEndIndex = Html
string ThirdWindforce = Html
if (ThirdWindforce
{
}
else if (ThirdWindforce
{
string strWindforce = ThirdWindforce
int minWindforce = Int
ThirdWindforce = ThirdWindforce
}
else if (ThirdWindforce
{
string strWindforce = ThirdWindforce
int minWindforce = Int
ThirdWindforce = ThirdWindforce
}
#endregion
al
al
al
al
al
al
al
al
al
al
al
al
al
al
al
al
al
al
}
catch (Exception err)
{
}
return al;
}
特殊說明
另外
再補充一點
From:http://tw.wingwit.com/Article/program/net/201311/13478.html