asp显示天气预报代码(天气预报链接代码)
admin 发布:2022-12-19 11:26 96
本篇文章给大家谈谈asp显示天气预报代码,以及天气预报链接代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
我想要在asp页面中实现实时天气预报的功能
从网上搜索天气预报特效代码 打开网页选择你要显示的天气预报的地区 然后获取代码 把代码放到你的网站上就行了。
求个在内网网站上显示天气预报的ASP代码
如果内网与外网不互通。这种代码是没有的。
如果是内网与外网联通,百度搜索天气预报代码即可。很多可用的。
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.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;
}
}
关于asp显示天气预报代码和天气预报链接代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-14交易链接大全,交易链接是什么意思
- 05-09网页代码,网页代码快捷键
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
- 05-06在线html执行代码(html怎么运行)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06代码源软件库(程序代码库)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接