本文目錄一覽:
- 1、java如何調用sina微博介面
- 2、JAVA編程利用Object getContent()方法獲得某一URL地址(如新浪,搜狐,網易
- 3、請問怎樣用Java獲取股票行情歷史數據?新浪、搜狐、百度財經都可以……
java如何調用sina微博介面
你查看下新浪微博api 仔細的看看
點先申請一個應用的key 和 密鑰
調用要先登陸一個賬號 這個新浪api里說的很清楚 就是跳轉到他的頁面登陸 登陸成功就可以調用已有的介面 如果你有別的需求開發可以用http的方式來抓取頁面
JAVA編程利用Object getContent()方法獲得某一URL地址(如新浪,搜狐,網易
String res = “”;
HttpURLConnection urlconnection = null;
URL urlcon = new URL(url);
// 打開連接
urlconnection = (HttpURLConnection) urlcon.openConnection();
// 配置連接的請求的內容
urlconnection.setRequestProperty(“Content-Type”, contentType);
// 打開讀寫屬性,默認均為false
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
// 設置請求方式,默認為GET
urlconnection.setRequestMethod(requestMethod);
// Post 請求不使用緩存
urlconnection.setUseCaches(false);
//設置連接主機超時(單位:毫秒)
urlconnection.setConnectTimeout(timeOut);
// 打開請求連接
urlconnection.connect();
BufferedReader in = null;
try
{
in = new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
String inputLine = null;
while ( (inputLine = in.readLine()) != null)
{
res += inputLine;
}
res = res.trim();
in.close();
}
finally
{
if (in != null)
{
in.close();
}
urlconnection.disconnect();
}
return res;
請問怎樣用Java獲取股票行情歷史數據?新浪、搜狐、百度財經都可以……
public class StockConnection {
public static void main(String[] args) {
URL ur = null;
try {
//搜狐股票行情歷史介面
// ur = new URL(“;start=20130930end=20131231stat=1order=Dperiod=dcallback=historySearchHandlerrt=jsonp”);
//新浪股票行情歷史介面
ur = new URL(“;rand=random(10000)symbol=sh600000end_date=20150809begin_date=20000101type=plain”);
HttpURLConnection uc = (HttpURLConnection) ur.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(ur.openStream(),”GBK”));
String line;
while((line = reader.readLine()) != null){
System.out.println(line);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
原創文章,作者:LD94E,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/130109.html