您现在的位置是: 首页 > 天气应用 天气应用
透明天气预报代码
zmhk 2024-06-05 人已围观
简介透明天气预报代码 很高兴有机会参与这个透明天气预报代码问题集合的讨论。这是一个多元且重要的话题,我将采取系统的方法,逐一回答每个问题,并分享一些相关的案例和观点。1.求~一行天气预报代码(附参考站)
很高兴有机会参与这个透明天气预报代码问题集合的讨论。这是一个多元且重要的话题,我将采取系统的方法,逐一回答每个问题,并分享一些相关的案例和观点。
1.求~一行天气预报代码(附参考站)
2.求天气预报代码
3.html添加天气预报代码
4.小学四年级科学表示气象符号有哪些
5.php获取天气预报的代码
6.ASP.NET实现天气预报
求~一行天气预报代码(附参考站)
发送到这个网站的一个网址,会自动返回此城市的天气信息。对此信息再格式化就好了。
发送:酒嘉市场信息网
这是泰安的天气预报代码,看你需要那种样式
样式一代码:<iframe src="/wmaps/xml/%s.xml";
$chinaURL?=?sprintf($URLStyle,?"china");
$chinaStr?=?file_get_contents($chinaURL);
$chinaObj?=?simplexml_load_string($chinaStr);
$chinaObjLen?=?count($chinaObj->city);
echo?"chinaObjLen?=?".$chinaObjLen."\n";
for?($i=0;$i<$chinaObjLen;$i++){
//遍历省一级节点,共37个
$level1?=?$chinaObj->city[$i]["pyName"];
$shengjiURL?=?sprintf($URLStyle,?$level1);
$shengjiStr?=?file_get_contents($shengjiURL);
//echo?$shengjiStr;
$shengjiObj?=?simplexml_load_string($shengjiStr);?
$shengjiObjLen?=?count($shengjiObj->city);
//?echo?$chinaObj->city[$i]["quName"];
//?echo?"?".$shengjiObjLen."\n";
for?($j=0;$j<$shengjiObjLen;$j++){
//遍历市一级节点
$level2?=?$shengjiObj->city[$j]["pyName"];
$shijiURL?=?sprintf($URLStyle,?$level2);
$shijiStr?=?file_get_contents($shijiURL);
//echo?$shijiStr;
$shijiObj?=?simplexml_load_string($shijiStr);?
//直辖市和海南、台湾、钓鱼岛等没有县级节点if(!$shijiObj){
echo?"WARNNING:?not?exsit?next?level?node.?-?".$level1."-".$shijiURL."\n";
echo?'?"'.$shengjiObj->city[$j]["cityname"].'"?=>?';
echo?$shengjiObj->city[$j]["url"].",\n";
continue;
}
$shijiObjLen?=?count($shijiObj->city);
//echo?$shengjiObj->city[$j]["cityname"]."?";
//echo?$shijiObjLen."\n";
for?($k=0;$k<$shijiObjLen;$k++){
//遍历县一级节点
$xianji_code?=?$shijiObj->city[$k]["url"];
echo?'?"'.$shijiObj->city[$k]["cityname"].'"?=>?';
echo?$shijiObj->city[$k]["url"].",\n";
//echo?$xianji_code."\n";?
}
}
}
//print_r($chinaObj);
>通过XML接口根节点递归获得全国几千个县以上城市cide code的代码
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("/iframe/weather/" + 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;
}
}
今天关于“透明天气预报代码”的探讨就到这里了。希望大家能够更深入地了解“透明天气预报代码”,并从我的答案中找到一些灵感。