您现在的位置是: 首页 > 实时天气 实时天气
获取天气预报代码_天气位置代码
tamoadmin 2024-06-24 人已围观
简介1.谁有根据IP显示天气预报的代码啊?要一行字的2.最好的网页天气预报代码(自动定制城市天气)3.VB 怎么实现点击按钮自动获取天气预报4.求~一行天气预报代码(附参考站)using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.
1.谁有根据IP显示天气预报的代码啊?要一行字的
2.最好的网页天气预报代码(自动定制城市天气)
3.VB 怎么实现点击按钮自动获取天气预报
4.求~一行天气预报代码(附参考站)
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.HtmlControls;
using System.Data.SqlClient;
using System.Net;
using System.IO;
using System.Collections;
/// <summary>
/// Weather 的摘要说明
/// </summary>
public class Weather
{
public Weather()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string ConvertCodeByCity(string City)
{
string Code = "";
switch (City)
{
case "北京":
Code = "110100";
break;
default:
break;
}
return Code;
}
public static ArrayList GetWeather(string code)
{
/*
[0] "北京 "string
[1] "雷阵雨 "string
[2] "9℃" string
[3] "29℃"string
[4] "小于3级"string
*/
string html = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("" + code + "_w.html ");
request.Method = "Get";
//request.Timeout = 1;
request.ContentType = "application/x-www-form-urlencoded ";
WebResponse response = request.GetResponse();
Stream s = response.GetResponseStream();
StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("GB2312"));
html = sr.ReadToEnd();
s.Close();
sr.Close();
}
catch (Exception err)
{
throw new Exception("访问地址出错~~~ ");
}
int count = html.Length;
int starIndex = html.IndexOf("<table ", 0, count);
int endIndex = html.IndexOf("</table>", starIndex, count - starIndex);
html = html.Substring(starIndex, endIndex - starIndex + 8);
//得到城市
int cityStartIndex = html.IndexOf("<b>", 0, html.Length);
int cityEndIndex = html.IndexOf("</b>", 0, html.Length);
string City = html.Substring(cityStartIndex + 3, cityEndIndex - cityStartIndex - 3);
//得到天气
int weatherStartIndex = html.IndexOf("<b>", cityEndIndex);
int weatherEndIndex = html.IndexOf("</b>", weatherStartIndex);
string Weather = html.Substring(weatherStartIndex + 3, weatherEndIndex - weatherStartIndex - 3);
//得到温度
int temperatureStartIndex = html.IndexOf("<b", weatherEndIndex);
int temperatureEndIndex = html.IndexOf("</b>", weatherEndIndex + 3);
string Temperature = html.Substring(temperatureStartIndex + 21, temperatureEndIndex - temperatureStartIndex - 21);
int int1 = Temperature.IndexOf("℃", 0);
int int2 = Temperature.IndexOf("~", 0);
int int3 = Temperature.IndexOf("℃", int2);
string MinTemperature = Temperature.Substring(int2 + 1, int3 - int2);
string MaxTemperature = Temperature.Substring(0, int2 - int1 + 2);
//得到风力
int windforceStartIndex = html.IndexOf("风力:", temperatureEndIndex);
int windforceEndIndex = html.IndexOf("<br>", windforceStartIndex);
string Windforce = html.Substring(windforceStartIndex + 3, windforceEndIndex - windforceStartIndex - 3);
if (Windforce.Contains("小于") && (!Windforce.Contains("等于"))) //判断风力是否含有"小于"或"小于等于"字样将,如果有的话,将其替换为2-
{
//Windforce = Windforce.Replace("小于", "2-");
string strWindforce = Windforce.Substring(2, Windforce.Length - 3);
int minWindforce = Int32.Parse(strWindforce) - 1;
Windforce = Windforce.Replace("小于", minWindforce.ToString() + "-");
}
else if (Windforce.Contains("小于等于"))
{
string strWindforce = Windforce.Substring(4, Windforce.Length - 5);
int minWindforce = Int32.Parse(strWindforce) - 1;
Windforce = Windforce.Replace("小于等于", minWindforce.ToString() + "-");
}
ArrayList al = new ArrayList();
al.Add(City);
al.Add(Weather);
al.Add(MinTemperature);
al.Add(MaxTemperature);
al.Add(Windforce);
return al;
}
}
谁有根据IP显示天气预报的代码啊?要一行字的
直接使用插件,如
<iframe width="214" scrolling="no" height="54" frameborder="0" allowtransparency="true" src=""></iframe>
效果如下
这个插件来源是 style="font-size: 18px;font-weight: bold;border-left: 4px solid #a10d00;margin: 10px 0px 15px 0px;padding: 10px 0 10px 20px;background: #f1dada;">最好的网页天气预报代码(自动定制城市天气)
第一款
<iframe src="" width="334" height="23" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" name="I2" align="middle">
</iframe> 可自定城市
第二款
<iframe src="" frameborder="0" width="160" height="15" marginheight="0" marginwidth="0" scrolling="no"></iframe> 一行字
VB 怎么实现点击按钮自动获取天气预报
这是你想要的天气预报代码,由中央气象台提供数据,最准确最权威的天气预报,能够根据访客不同的IP地址显示不同城市的天气预报
下面是源程序代码:
<iframe src="" width="160" height="60" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
求~一行天气预报代码(附参考站)
为了方便,文本框改成数组控件。代码中用北京作为天气预报地点,改的话将网址改下即可,具体方法可以百度。另外,新浪天气预报只有4天。最后说明一下,除了标签和文本框,没用其它控件。
发送到这个网站的一个网址,会自动返回此城市的天气信息。对此信息再格式化就好了。
发送:广州
返回:b4.gif^广州^雷阵雨^26℃ ~ 22℃^微风^紫外线:弱
发送:上海
返回:b3.gif^上海^阵雨转阴^16℃ ~ 13℃^东南风3-4级^紫外线:最弱
至于如何判断访问者是哪一个城市,需要分析其IP地址然后再加判断吧,你到网上找个IP转城市的数据库看看。