Reputation: 429
Using OracleSQL and Java
I have a "TickerSymbol Database" and a "Stockquote Database".
Selecting TickerSymbols from "GOOG","APPL","FB", and "AMZN" from the "TickerSymbolDatabase"
and circulating the ticker symbols at the end of YahooFinance URL.
http://finance.yahoo.com/q?s= (TICKER)
Then finding the stock quote, and inserting the quote data into the "Stockquote Database".
I'm not exactly sure how to use the Jsoup selector, or how to circulate the ticker symbols at the end of the YahooFinance URL
Upvotes: 1
Views: 3147
Reputation: 10522
Here's a simple example. Please check the TOS, and you might prefer Stanley's suggestion of fetching via CSV. I wanted to show how to fetch it in jsoup. Getting it into Oracle is a different question.
String[] codes = {"TSLA", "F", "TM"};
String baseUrl = "http://finance.yahoo.com/q?s=";
String ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.33 (KHTML, like Gecko) Chrome/27.0.1438.7 Safari/537.33";
for (String code : codes) {
String url = baseUrl + code;
Document doc = Jsoup.connect(url).userAgent(ua).timeout(10*1000).get();
String price = doc.select(".time_rtq_ticker").first().text();
String name = doc.select(".title h2").first().text();
System.out.println(String.format("%s [%s] is trading at %s", name, code, price));
}
This outputs:
Tesla Motors, Inc. (TSLA) [TSLA] is trading at 135.45
Ford Motor Co. (F) [F] is trading at 17.07
Toyota Motor Corporation (TM) [TM] is trading at 127.98
I like to use Try jsoup to test and debug URL responses and selectors queries.
Upvotes: 1
Reputation: 397
The output file such as Apple Inc Stock Data at http://finance.yahoo.com/q;_ylt=Ag5D9mq4OAYIeUaL64JN7QYDyr0F;_ylc=X1MDMjE0MjQ3ODk0OARfcgMyBGZyA3VoM19maW5hbmNlX3dlYl9ncwRmcjIDc2EtZ3AEZ3ByaWQDBG5fZ3BzAzEwBG9yaWdpbgNmaW5hbmNlLnlhaG9vLmNvbQRwb3MDMQRwcXN0cgMEcXVlcnkDQUFQTCwEc2FjAzEEc2FvAzE-?p=http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3DAAPL%26ql%3D0&type=2button&fr=uh3_finance_web_gs&uhb=uhb2&s=AAPL is a CSV file. You could just read the content and parse by comma delimitor.
Upvotes: 0