我只想得到城市和温度,我试过这个:
HttpParams httpParameters = new BasicHttpParams();
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpGet httpget = new HttpGethttp://netmobileag.accu weather.com/widget/netmobileag/weather-data.asp?slat=48.04960&slon=21.71420&metric=1");
HttpResponse response = httpclient.execute(httpget);
InputStream in = response.getEntity().getContent();
String res = "";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(in));
doc.getDocumentElement().normalize();
NodeList loc = doc.getElementsByTagName("local");
for (int i = 0; i < loc.item(0).getChildNodes().getLength(); i++) {
res = res + "\n" + loc.item(0).getChildNodes().item(0).getNodeValue();
}
但资源将是
#text
#text
...
总结 25 倍。如何获取城市和温度值?