標題:
Google stock
[打印本頁]
作者:
ray
時間:
2012-11-19 19:37
標題:
Google stock
protected String getGooglePrice(String ss)
{
try
{
}
catch(Exception e)
{
e.printStackTrace();
}
return "連線發生問題,請稍候再試!";
}
複製代碼
作者:
ray
時間:
2012-11-19 19:43
URL url = new URL(GOOGLE_URL+ss);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(url.openStream());
複製代碼
作者:
ray
時間:
2012-11-19 20:02
本帖最後由 ray 於 2012-11-19 20:09 編輯
doc.getDocumentElement().normalize();
info = "公司名稱:" + parseGoogleXML(doc,"company") + "\n";
info += "價格時間:" + parseGoogleXML(doc,"trade_date_utc") + " " + parseGoogleXML(doc,"trade_time_utc") + "\n";
info += "目前價格:" + parseGoogleXML(doc,"last") + "\n";
info += "昨天收盤:" + parseGoogleXML(doc,"y_close") + "\n";
info += "今天開盤:" + parseGoogleXML(doc,"open") + "\n";
info += "今天最高:" + parseGoogleXML(doc,"high") + "\n";
info += "今天最低:" + parseGoogleXML(doc,"low") + "\n";
info += "張跌金額:" + parseGoogleXML(doc,"change") + "\n";
info += "張跌比率:" + parseGoogleXML(doc,"perc_change") + "\n";
return info;
複製代碼
作者:
ray
時間:
2012-11-19 20:09
String parseGoogleXML(Document doc,String pattern)
{
NodeList elements = doc.getElementsByTagName(pattern);
return ((Element)elements.item(0)).getAttribute("data");
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2