您的位置:首页 > 移动开发 > Android开发

使用java获取未来7天天气信息,可用于android

2013-01-29 00:14 495 查看
环境:eclipsse, jdk1.6, 没有使用第三方的包,都是JDK有的。

项目结构如下:



下载地址:
http://download.csdn.net/detail/wssiqi/5037597
注意,项目源文件我都使用的是UTF-8的编码格式,如果不是,会显示乱码。

设置UTF-8:windows->Preferences->General->Workspace 页面上Text file encoding,选择Other UTF-8

1.获取天气预报的类

WeatherUtil.java

package com.siqi.weather;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Hashtable;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
* 中国气象频道手机版("http://m.weathercn.com")获取天气信息, 因为手机版网页内容小,访问速度快。
*
* @author siqi
*
*/
public class WeatherUtil {

/**
* 省份页面(省)
*/
public static final String PROVINCE_URL = "http://m.weathercn.com/common/province.jsp";
/**
* 城市页面(市)<br/>
* pid=%s中%s表示城市编号 例:http://m.weathercn.com/common/dis.do?pid=010101
*/
public static final String DISTRICT_URL = "http://m.weathercn.com/common/dis.do?pid=%s";
/**
* 县区页面(区)<br/>
* did=%s中%s表示县区编号<br/>
* pid=%s中%s表示城市编号<br/>
* 例:http://m.weathercn.com/common/cout.do?did=01010101&pid=010101
*/
public static final String COUNTY_URL = "http://m.weathercn.com/common/cout.do?did=%s&pid=%s";
/**
* 7天天气预报页面<br/>
* cid=%s中%s表示区编号<br/>
* 例:http://m.weathercn.com/common/7d.do?cid=0101010110
*/
public static final String REPORT7_URL = "http://m.weathercn.com/common/7d.do?cid=%s";
/**
* 生活指数页面<br/>
* cid=%s中%s表示区编号
*/
public static final String REPORT_MORE_URL = "http://m.weathercn.com/common/zslb.do?cid=%s";

/**
* 保存城市编码信息的xml文档<br/>
* 保存了具体的区县和区县所对应的编码,例如<br/>
* <county><br/>
* <name>北京</name><br/>
* <code>0101010110</code><br/>
* </county>
*/
public static final String XML_FILE = "./weathercn.xml";

private List<WeatherReport> weatherReportList = new ArrayList<WeatherReport>();

/**
* 启动的时候,首先检查weathercn.xml是否存在,如果不存在的话,重新从m.weathercn.com获取,
* 只有第一次的时候会获取。
*/
static {
try {
prepareXML();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 返回指定城市,指定日期的天气预报。<br/>
*
* @param city
*            城市,如"北京"。
* @param cal
*            日期。
* @return 如果城市正确,并且日期在7天以内,那么返回天气信息。否则返回null。
*/
public WeatherReport getWeatherReport(String city, Calendar cal) {
String dateStr = cal.get(Calendar.MONTH) + "月"
+ cal.get(Calendar.DAY_OF_MONTH) + "日";
return getWeatherReport(city, dateStr);
}

/**
* 返回指定城市,指定日期的天气预报。<br/>
*
* @param city
*            城市,如"北京"。
* @param date
*            日期,格式为"1月20日"。
* @return 如果城市正确,并且日期在7天以内,那么返回天气信息。否则返回null。
*/
public WeatherReport getWeatherReport(String city, String date) {
for (WeatherReport report : getWeatherReports(city)) {
if (report.getDate().equals(date)) {
return report;
}
}

return null;
}

/**
* 返回指定城市的天气预报(7天内)
*
* @param city
* @return 返回指定城市的天气预报(7天内),如果指定的城市错误,返回空的list,list.size()=0
*/
public List<WeatherReport> getWeatherReports(String city) {
List<WeatherReport> list = new ArrayList<WeatherReport>();
try {

String weatherPage = getWeatherReportPage(city);

List<String> reportStrList = getAllMathers(weatherPage,
"(?<=class=\"b\">)[\\s\\S]+?<br>[\\s\\S]+?(?=</)");
for (String reportStr : reportStrList) {
String weather = reportStr.trim().replaceAll(" ", "")
.replaceAll("<br>\r\n\r\n", "\r\n")
.replaceAll("<br>", "");

String[] str = weather.split("\r\n");
if (str.length > 5) {
WeatherReport report = new WeatherReport();

int i = 0;
String dateStr = str[i++].trim();

report.setCity(city);
report.setDate(getMatcher(dateStr, ".+(?=\\()"));
report.setWeekDay(getMatcher(dateStr, "(?<=\\().+?(?=\\))"));
report.setDayOrNight(str[i++].trim());
report.setWeather(str[i++].trim());
report.setTemperature(str[i++].trim());
report.setWindDir(str[i++].trim());
report.setWind(str[i++].trim());

list.add(report);
if (str.length > 10) {
report = new WeatherReport();
report.setCity(city);
report.setDate(getMatcher(dateStr, ".+(?=\\()"));
report.setWeekDay(getMatcher(dateStr,
"(?<=\\().+?(?=\\))"));
report.setDayOrNight(str[i++].trim());
report.setWeather(str[i++].trim());
report.setTemperature(str[i++].trim());
report.setWindDir(str[i++].trim());
report.setWind(str[i++].trim());
list.add(report);
}
}
}

} catch (Exception e) {
e.printStackTrace();
}

this.weatherReportList = list;
return this.weatherReportList;

}

/**
* 返回字符串中第一个符合regex的字符串,如果没有符合的,返回空字符串
*
* @param str
*            字符串
* @param regex
*            正则表达式
* @return
*/
public static String getMatcher(String str, String regex) {
Matcher mat = Pattern.compile(regex).matcher(str);
if (mat.find()) {
return mat.group();
} else {
return "";
}
}

/**
* 返回字符串str中所有符合regex的子字符串。
*
* @param str
* @param regex
* @return
*/
public static List<String> getAllMathers(String str, String regex) {
List<String> strList = new ArrayList<String>();
Matcher mat = Pattern.compile(regex).matcher(str);
while (mat.find()) {
strList.add(mat.group());
}
return strList;
}

/**
* 从m.weathercn.com获取城市(区域county)和城市所对应的编号(区域编号cid)。<br/>
* 并保存到xml文件"weathercn.xml"。如果已经存在weathercn.xml文件,那么不会再次获取。
*
* @throws Exception
*/
private static void prepareXML() throws Exception {
/**
* 如果xml文件已经存在,不用再次获取。
*/
File file = new File(XML_FILE);
if (file.exists()) {
// 提示xml文件位置,不需要可以注释掉。
System.out.println("在下面的路径中找到XML文件 " + file.getCanonicalPath());
return;
}

// 用DOM创建XML文档
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
// 创建XML文档root element
Element root = doc.createElement("root");
doc.appendChild(root);

// 省province
//
WebPageUtil webPageUtil = new WebPageUtil().processUrl(PROVINCE_URL);

String provincePage = webPageUtil.getWebContent();
Hashtable<String, String> provinceTable = parseProvincePage(provincePage);
for (String province : provinceTable.keySet()) {
// 进度提示,不需要可以注释掉
System.out.println(String.format("正在获取%s的城市信息...", province));
Element eleProvince = doc.createElement(province);
eleProvince.setAttribute("pid", provinceTable.get(province));
root.appendChild(eleProvince);

String districtPage = new WebPageUtil().processUrl(
String.format(DISTRICT_URL, provinceTable.get(province)))
.getWebContent();

Hashtable<String, String> districtTable = parseDistrictPage(districtPage);
for (String district : districtTable.keySet()) {
Element eleDistrict = doc.createElement(district);
eleDistrict.setAttribute("did", districtTable.get(district));
eleProvince.appendChild(eleDistrict);

// long time = System.currentTimeMillis();
String countyPage = new WebPageUtil().processUrl(
String.format(COUNTY_URL, districtTable.get(district),
provinceTable.get(province))).getWebContent();
Hashtable<String, String> countyTable = parseCountyPage(countyPage);
for (String county : countyTable.keySet()) {
Element eleCounty = doc.createElement(county);
eleCounty.setAttribute("cid", countyTable.get(county));
eleDistrict.appendChild(eleCounty);
// System.out.println(String.format("%s->%s->%s %s",
// province, district, county,
// System.currentTimeMillis()-time));

}
}
// 进度提示,不需要可以注释掉
System.out.println(String.format("已成功获取%s的城市信息", province));
}

// 将获取到的信息保存到xml文件中
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(file);
transformer.transform(source, result);
System.out.println("XML文件已经被成功创建 " + file.getCanonicalPath());

}

/**
* 从m.weathercn.com的市页面中获取区县信息。<br/>
* 例如:从成都市页面中获取新津,双流等区县的编号。
*
* @param page
* @return
*/
public static Hashtable<String, String> parseCountyPage(String page) {

return getKeyValues(page,
"<a href=\"index.do\\?cid=?.+?&pid=.+?class=\"c\">.+?</a>",
"(?<=>).+?(?=</a>)", "(?<=cid=)[0-9]+");
}

/**
* 从m.weathercn.com的省页面中获取省市信息。<br/>
* 例如:从四川省的页面获取成都,绵羊等市的编号。
*
* @param page
* @return
*/
public static Hashtable<String, String> parseDistrictPage(String page) {

return getKeyValues(page, "<a href=\"cout.do\\?.+?class=\"c\">.+?</a>",
"(?<=>).+?(?=</a>)", "(?<=did=)[0-9]+");
}

/**
* 从m.weathercn.com的国内页面中获取省市信息。<br/>
* 例如:从国内页面获取四川省,山东省,北京市等的编号。
*
* @param page
* @return
*/
public static Hashtable<String, String> parseProvincePage(String page) {

return getKeyValues(page, "<a href=\"dis.do?.+?class=\"c\">.+?</a>",
"(?<=>).+?(?=</a>)", "(?<=pid=)[0-9]+");
}

/**
* 从页面里面获取所需要的信息。
*
* @param webPage
*            网页
* @param tagRegex
*            正则表达式,用以获取包含key和value的内容,保存在字符串tag中
* @param keyRegex
*            正则表达式,用以从tag获取key的值
* @param valueRegex
*            正则表达式,用以从tag获取value的值
* @return 返回网页中所有匹配的key和value,如果没有,返回一个空的table,table.size()=0
*/
public static Hashtable<String, String> getKeyValues(String webPage,
String tagRegex, String keyRegex, String valueRegex) {
Hashtable<String, String> table = new Hashtable<String, String>();

for (String tag : getAllMathers(webPage, tagRegex)) {
table.put(getMatcher(tag, keyRegex), getMatcher(tag, valueRegex));
}

return table;
}

/**
* 获取指定城市或者区域的天气预报页面。
*
* @param city
*            城市
* @return 返回天气预报页面的源代码。错误或者城市不正确等则返回空字符串。
* @throws Exception
*/
public String getWeatherReportPage(String city) throws Exception {
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(XML_FILE);
NodeList nodeList = doc.getElementsByTagName(city);
for (int i = 0; i < nodeList.getLength(); i++) {
Element ele = (Element) nodeList.item(i);
if (!ele.getAttribute("cid").equals("")) {
return new WebPageUtil().processUrl(
String.format(REPORT7_URL, ele.getAttribute("cid")))
.getWebContent();
}
}
return "";
}
}


2.获取网页内容的类

WebPageUtil.java

做了一下修改:
//清空上次获取的数据
this.msgHeader = "";
this.msgHeaderBuffer.setLength(0);
this.bytes = new byte[0];
原来的没有这3行代码,在获取一个网页内容后,继续获取另一个网页是,由于没有清空上次获取的内容,会报错。

package com.siqi.weather;

import java.io.InputStream;
import java.net.Socket;
import java.nio.charset.Charset;
//import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* 一个简单的类,用来获取网页内容
* @author siqi
*
*/
public class WebPageUtil {

/**
* 调试
*/
private static boolean debug = false;

/**
* 消息头,包含http资源或者http服务器的一些属性,例如:<BR/>
* HTTP/1.1 200 OK<BR/>
* Server: nginx/0.7.68<BR/>
* Date: Tue, 22 Jan 2013 10:55:21 GMT<BR/>
* Content-Type: image/jpeg<BR/>
* Content-Length: 6372<BR/>
* Last-Modified: Sun, 29 Apr 2012 07:29:01 GMT<BR/>
* Connection: close<BR/>
* Expires: Mon, 18 Nov 2013 10:55:21 GMT<BR/>
* Cache-Control: max-age=25920000<BR/>
*/
private String msgHeader;
/**
* 消息头的字符缓存
*/
private StringBuffer msgHeaderBuffer = new StringBuffer();

/**
* 网页内容编码
*/
private Charset charset;

/**
* 缓存大小(单位:字节)
*/
private int buffer_size = 4096;

/**
* 网页内容
*/
private byte[] bytes = new byte[0];

//    /**
//     * 一个调用WebUtil的例子
//     *
//     * @param args
//     */
//    public static void main(String[] args) {
//        try {
//            String url = "http://m.weathercn.com/common/province.jsp";
//            WebPageUtil webPageUtil = new WebPageUtil().processUrl(url);
//            System.out.println("=======Header :=======\r\n"+webPageUtil.getMsgHeader());
//            System.out.println("=======Content:=======\r\n"+webPageUtil.getWebContent());
//            webPageUtil.processUrl("http://www.baidu.com");
//            System.out.println("=======Header :=======\r\n"+webPageUtil.getMsgHeader());
//            System.out.println("=======Content:=======\r\n"+webPageUtil.getWebContent());
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

/**
* 使用Socket请求(获取)一个网页。<br/>
* 例如:<br/>
* processUrl("http://www.baidu.com/")会获取百度首页;<br/>
*
* @param url
*            这个网页或者网页内容的地址
* @throws Exception
*/
public WebPageUtil processUrl(String url) throws Exception {

//清空上次获取的数据
this.msgHeader = "";
this.msgHeaderBuffer.setLength(0);
this.bytes = new byte[0];

url = formatUrl(url);

// 设置要连接的服务器地址
Socket socket = new Socket(getHost(url), getPort(url));
socket.setSoTimeout(3000);

// 构造请求,详情请参考HTTP协议(RFC2616)
String request = String.format("GET %s HTTP/1.0\r\n", getSubUrl(url));
request += String.format("HOST: %s \r\n\r\n", getHost(url));

if(debug) {
System.out.println("request:\r\n"+request);
}

// 发送请求
socket.getOutputStream().write(request.getBytes());

// 设置缓存,最好跟系统的socket接收缓存一样
this.buffer_size = socket.getReceiveBufferSize();
byte[] bytesBuffer = new byte[buffer_size];// 缓存InputStream的原始数据
char[] charsBuffer = new char[buffer_size];// 缓存InputStream的字符数据

// 来自服务器响应(InputStream)
InputStream is = socket.getInputStream();

// 局部变量,读取到的内容长度(字节)
int bytesLength = 0;
// 局部变量,判断消息头是否读取完毕
boolean headerComplete = false;

// 从InputStream中读取网页的内容,如果读取到的内容
// 长度为-1,则读取完毕
while ((bytesLength = is.read(bytesBuffer, 0, buffer_size)) != -1) {
if (headerComplete) {
SaveBytes(bytesBuffer, 0, bytesLength);
} else {
int bufferLength = msgHeaderBuffer.length();
msgHeaderBuffer.append(
bytes2chars(bytesBuffer, charsBuffer, bytesLength), 0,
bytesLength);
int msgEndIndex = msgHeaderBuffer.indexOf("\r\n\r\n");
if (msgEndIndex != -1) {
headerComplete = true;
msgHeader = "Url: " + url + "\r\n"
+ msgHeaderBuffer.substring(0, msgEndIndex);
int temp = msgEndIndex - bufferLength + 4;
SaveBytes(bytesBuffer, temp, bytesLength - temp);
}
}
}

socket.close();

//获取网页编码
this.getCharset();

return this;
}

/**
* 根据网址获取服务器端口。<br/>
* http 端口为80<br/>
* https端口为443
* @param url
* @return
*/
public static int getPort(String url) {
int port = 0;
if (url.startsWith("https://")) {
port = 443;
} else if (url.startsWith("http://")) {
port = 80;
}

if(debug) {
System.out.println("port: "+port);
}

return port;
}

/**
* 根据网址,获取服务器地址<br/>
* 例如:<br/>
* http://m.weathercn.com/common/province.jsp<p> * 返回:<br/>
* m.weathercn.com
* @param url 网址
* @return
*/
public static String getHost(String url) {
String host = "";
Matcher mat = Pattern.compile("(?<=https?://).+?(?=/)").matcher(url);
if(mat.find()) {
host = mat.group();
}

if(debug) {
System.out.println("host: "+host);
}

return host;
}

/**
* 根据网址,获取网页路径
* 例如:<br/>
* http://m.weathercn.com/common/province.jsp<p> * 返回:<br/>
* /common/province.jsp
* @param url
* @return 如果没有获取到网页路径,返回"";
*/
public static String getSubUrl(String url) {
String subUrl = "";
Matcher mat = Pattern.compile("https?://.+?(?=/)").matcher(url);
if(mat.find()) {
subUrl = url.substring(mat.group().length());
}

if(debug) {
System.out.println("subUrl: "+subUrl);
}

return subUrl;
}

/**
* 在某些网址上加个"/"<br/>
* 例如:<br/>
* http://www.baidu.com<br/> * 返回:<br/>
* http://www.baidu.com/<p> * 例如:<br/>
* http://www.baidu.com/xxxx<br/> * 返回:(没有加"/")<br/>
* http://www.baidu.com/xxxx<br/> * @param url
* @return
*/
public static String formatUrl(String url) {
Matcher mat = Pattern.compile("https?://[^/]+").matcher(url);
if (mat.find() && mat.group().equals(url)) {
return url + "/";
} else {
return url;
}
}

/**
* 把从输入流中读取到的数据保存到bytes数组中,
* 每次都创建一个新的byte[]来存储原来bytes[]数组中的数据和
* 新读取到的b中的数据。
* @param b 存储内容的byte[]
* @param start 内容的起始位置,从0开始
* @param length 内容的长度
* @throws Exception
*/
private void SaveBytes(byte[] b, int start, int length) throws Exception {
//do some check
if(start<0 || length<0) {
throw new Exception("start/length is incorrect.");
}
//新建一个byte数组
byte[] newBytes = new byte[bytes.length+length];
System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
System.arraycopy(b, start, newBytes, bytes.length, length);

bytes = newBytes;

}

/**
* 将字节数据转换成字符数据
* @param srcBytes
* @param dstChars
* @param length
* @return
*/
private char[] bytes2chars(byte[] srcBytes, char[] dstChars, int length) {
for (int i = 0; i < length; i++) {
dstChars[i] = (char) srcBytes[i];
}

return dstChars;
}

/**
* 获取网页资源(文件)的消息头,里面包含了服务器和资源的一些属性
*/
public String getMsgHeader() {
return msgHeader;
}

/**
* 获取网页或网页资源的编码,如果在消息头里面没有找到编码,那么就
* 返回系统默认编码。
* @return
*/
public Charset getCharset() {
String header = this.msgHeader.toUpperCase();
Matcher mat = Pattern.compile("CHARSET=.+").matcher(header);
if(mat.find()) {
this.charset = Charset.forName(mat.group().split("=")[1]);
}else{
this.charset = Charset.defaultCharset();
}
return charset;
}

/**
* 获取网页内容
* @return
*/
public String getWebContent() {
return new String(bytes, charset);
}
}


3.天气预报类

WeatherReport.java

package com.siqi.weather;

/**
* 天气预报类,天气预报的基本属性。
* @author siqi
*
*/
public class WeatherReport {

/**
* 城市(区县)
*/
private String city;
/**
* 日期
*/
private String date;
/**
* 星期几
*/
private String weekDay;
/**
* 天气
*/
private String weather;
/**
* 温度
*/
private String temperature;
/**
* 风向
*/
private String windDir;
/**
* 风力
*/
private String wind;

/**
* 白天还是晚上
*/
private String dayOrNight;

/**
* 获取天气预报的城市。
* @return
*/
public String getCity() {
return city;
}

/**
* 设置天气预报的城市。
* @param city
*/
public void setCity(String city) {
this.city = city;
}

/**
* 获取天气预报的日期,格式为"1月28日"
* @return
*/
public String getDate() {
return date;
}

/**
* 设置天气预报的日期,格式为"1月28日"
* @param date
*/
public void setDate(String date) {
this.date = date;
}

/**
* 获取天气预报的星期
* @return
*/
public String getWeekDay() {
return weekDay;
}

/**
* 设置天气预报的星期
* @param weekDay
*/
public void setWeekDay(String weekDay) {
this.weekDay = weekDay;
}

/**
* 获取天气
* @return
*/
public String getWeather() {
return weather;
}

/**
* 设置天气
* @param weather
*/
public void setWeather(String weather) {
this.weather = weather;
}

/**
* 获取温度
* @return
*/
public String getTemperature() {
return temperature;
}

/**
* 设置温度
* @param temperature
*/
public void setTemperature(String temperature) {
this.temperature = temperature;
}

/**
* 获取风向
* @return
*/
public String getWindDir() {
return windDir;
}

/**
* 设置风向
* @param windDir
*/
public void setWindDir(String windDir) {
this.windDir = windDir;
}

/**
* 获取风力
* @return
*/
public String getWind() {
return wind;
}

/**
* 设置风力
* @param wind
*/
public void setWind(String wind) {
this.wind = wind;
}

/**
* 获取天气预报是白天还是晚上
* @return
*/
public String getDayOrNight() {
return dayOrNight;
}

/**
* 设置天气预报是白天还是晚上
* @param dayOrNight
*/
public void setDayOrNight(String dayOrNight) {
this.dayOrNight = dayOrNight;
}

/**
* 天气预报的字符串
*/
public String toString() {
return "WeatherReport [city=" + city + ", date=" + date + ", weekDay="
+ weekDay + ", weather=" + weather + ", temperature="
+ temperature + ", windDir=" + windDir + ", wind=" + wind
+ ", dayOrNight=" + dayOrNight + "]";
}

}


4.测试,例

WeatherSample.java

package com.siqi.sample;

import java.util.List;

import com.siqi.weather.WeatherReport;
import com.siqi.weather.WeatherUtil;

public class WeatherSample {

/**
* 一个简单的应用
*
* @param args
*/
public static void main(String[] args) {
// 获取成都的天气预报信息。
String city = "海南";
System.out.println(city + "未来7天天气预报信息:");
List<WeatherReport> listReport = new WeatherUtil()
.getWeatherReports(city);
if (listReport.size() < 1) {
System.out.println("没有找到 " + city + " 的天气预报。");
} else {
for (WeatherReport report : listReport) {
System.out.println(report);
}
}
}

}


结果:

海南未来7天天气预报信息:
在下面的路径中找到XML文件 C:\workspaces\01_java\Weather\weathercn.xml
WeatherReport [city=海南, date=1月28日, weekDay=星期一, weather=晴, temperature=-14°C, windDir=, wind=微风, dayOrNight=夜晚]
WeatherReport [city=海南, date=1月29日, weekDay=星期二, weather=多云, temperature=1°C, windDir=, wind=微风, dayOrNight=白天]
WeatherReport [city=海南, date=1月29日, weekDay=星期二, weather=多云, temperature=-15°C, windDir=, wind=微风, dayOrNight=夜晚]
WeatherReport [city=海南, date=1月30日, weekDay=星期三, weather=多云, temperature=4°C, windDir=, wind=微风, dayOrNight=白天]
WeatherReport [city=海南, date=1月30日, weekDay=星期三, weather=多云, temperature=-12°C, windDir=, wind=微风, dayOrNight=夜晚]
WeatherReport [city=海南, date=1月31日, weekDay=星期四, weather=多云, temperature=4°C, windDir=, wind=微风, dayOrNight=白天]
WeatherReport [city=海南, date=1月31日, weekDay=星期四, weather=多云, temperature=-14°C, windDir=, wind=微风, dayOrNight=夜晚]
WeatherReport [city=海南, date=2月1日, weekDay=星期五, weather=晴, temperature=0°C, windDir=, wind=微风, dayOrNight=白天]
WeatherReport [city=海南, date=2月1日, weekDay=星期五, weather=多云, temperature=-16°C, windDir=, wind=微风, dayOrNight=夜晚]
WeatherReport [city=海南, date=2月2日, weekDay=星期六, weather=阴, temperature=-3°C, windDir=, wind=微风, dayOrNight=白天]
WeatherReport [city=海南, date=2月2日, weekDay=星期六, weather=晴, temperature=-17°C, windDir=, wind=微风, dayOrNight=夜晚]
WeatherReport [city=海南, date=2月3日, weekDay=星期日, weather=多云, temperature=0°C, windDir=, wind=微风, dayOrNight=白天]
WeatherReport [city=海南, date=2月3日, weekDay=星期日, weather=晴, temperature=-17°C, windDir=, wind=微风, dayOrNight=夜晚]


注:第一次执行的时候会在项目路径下面创建weathercn.xml,里面保存的是区县和区县编号信息。

正在获取云南的城市信息...
已成功获取云南的城市信息
正在获取湖北的城市信息...
已成功获取湖北的城市信息
正在获取河南的城市信息...
已成功获取河南的城市信息
正在获取四川的城市信息...
已成功获取四川的城市信息
正在获取青海的城市信息...
已成功获取青海的城市信息
正在获取台湾的城市信息...
已成功获取台湾的城市信息
正在获取辽宁的城市信息...
已成功获取辽宁的城市信息
正在获取浙江的城市信息...
已成功获取浙江的城市信息
正在获取山西的城市信息...
已成功获取山西的城市信息
正在获取广西的城市信息...
已成功获取广西的城市信息
正在获取吉林的城市信息...
已成功获取吉林的城市信息
正在获取陕西的城市信息...
已成功获取陕西的城市信息
正在获取内蒙古的城市信息...
已成功获取内蒙古的城市信息
正在获取福建的城市信息...
已成功获取福建的城市信息
正在获取宁夏的城市信息...
已成功获取宁夏的城市信息
正在获取河北的城市信息...
已成功获取河北的城市信息
正在获取江西的城市信息...
已成功获取江西的城市信息
正在获取重庆的城市信息...
已成功获取重庆的城市信息
正在获取黑龙江的城市信息...
已成功获取黑龙江的城市信息
正在获取甘肃的城市信息...
已成功获取甘肃的城市信息
正在获取北京的城市信息...
已成功获取北京的城市信息
正在获取香港的城市信息...
已成功获取香港的城市信息
正在获取湖南的城市信息...
已成功获取湖南的城市信息
正在获取安徽的城市信息...
已成功获取安徽的城市信息
正在获取山东的城市信息...
已成功获取山东的城市信息
正在获取天津的城市信息...
已成功获取天津的城市信息
正在获取贵州的城市信息...
已成功获取贵州的城市信息
正在获取广东的城市信息...
已成功获取广东的城市信息
正在获取上海的城市信息...
已成功获取上海的城市信息
正在获取海南的城市信息...
已成功获取海南的城市信息
正在获取西藏的城市信息...
已成功获取西藏的城市信息
正在获取新疆的城市信息...
已成功获取新疆的城市信息
正在获取江苏的城市信息...
已成功获取江苏的城市信息
正在获取澳门的城市信息...
已成功获取澳门的城市信息
XML文件已经被成功创建 C:\workspaces\01_java\Weather\weathercn.xml
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: