如何使用java获取雅虎财经上的股票信息
2013-04-01 10:33
405 查看
public void retrievePriceInfo(){
try {
URL priceInfo=new URL(PRICE_URL);
//open the URL connection to retrieve the price info.
InputStream in= priceInfo.openConnection().getInputStream();
if (in==null) {
logger.error("Open URL connection failed");
}
//get the current time.
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
this.setCurDate(df.format(new Date()));
//parse the retrieved data to get the price info.
try {
this.setPrice(IOUtils.toString(in,"UTF-8"));
} catch(Exception e) {
logger.error("parse price info failed."+e.getMessage());
e.printStackTrace();
return ;
}
logger.warn("price is: "+this.getPrice());
logger.warn("current time is: "+ curDate);
storPrice();
} catch (MalformedURLException e) {
logger.error(" Either no legal protocol could be found in a specification string or the string could not be parsed:"+e.getMessage());
e.printStackTrace();
return ;
} catch (IOException e) {
logger.error("Open URL connection failed"+e.getMessage());
e.printStackTrace();
return ;
}
return ;
}
try {
URL priceInfo=new URL(PRICE_URL);
//open the URL connection to retrieve the price info.
InputStream in= priceInfo.openConnection().getInputStream();
if (in==null) {
logger.error("Open URL connection failed");
}
//get the current time.
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
this.setCurDate(df.format(new Date()));
//parse the retrieved data to get the price info.
try {
this.setPrice(IOUtils.toString(in,"UTF-8"));
} catch(Exception e) {
logger.error("parse price info failed."+e.getMessage());
e.printStackTrace();
return ;
}
logger.warn("price is: "+this.getPrice());
logger.warn("current time is: "+ curDate);
storPrice();
} catch (MalformedURLException e) {
logger.error(" Either no legal protocol could be found in a specification string or the string could not be parsed:"+e.getMessage());
e.printStackTrace();
return ;
} catch (IOException e) {
logger.error("Open URL connection failed"+e.getMessage());
e.printStackTrace();
return ;
}
return ;
}
相关文章推荐
- 如何使用java代码获取RSS中信息
- 如何利用Java获取系统的信息(CPU、内存、各盘符使用情况)
- 如何使用java获取内存信息?
- 如何利用Java获取系统的信息(CPU、内存、各盘符使用情况)
- Java如何获取系统cpu、内存、硬盘信息
- 使用Java获取任意数据库的信息
- 使用Java获取系统信息的常用代码整理总结
- Java程序使用httpClient发送Url链接,并获取返回的数据信息
- java使用android aapt获取APK信息
- Java 通过使用File类获取文件信息
- [Java爬虫] 使用 HtmlUnit + Xpath 模拟点击、动态获取信息
- 如何使用 Yahoo! Finance stock API 获取股票数据
- Java如何获取系统信息(包括操作系统、jvm、cpu、内存、硬盘、网络、io等)
- 如何使用WMI获取进程信息
- Java 通过使用File类获取文件信息
- 如何用JAVA获取GOOGLE 地图经纬度,地址信息
- os环境下,使用bsd实现echo server并如何获取本地网络信息