如何从雅虎财务流中捕获数据?

时间:2011-08-15 10:30:30

标签: c# java html ajax tcp

雅虎财务流媒体使用不断增加文件大小的方法来更新数据:

http://uk.finance.yahoo.com/q?s= ^富时

无论如何我可以收集这些数据(我不打算出售它 - 想制作我自己的业余交易屏幕)?

2 个答案:

答案 0 :(得分:0)

如果您想解析HTML,我建议Apache Jericho。但是你最好找到一个RSS / JSON / XML流。

此致  斯特凡

答案 1 :(得分:0)

您可以获取HTML并解析出您想要的内容。以下是使用Apache客户端的一些基本代码:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

public class YahooFinanceScraper {

// HTTP GET the given URL
private static String HttpGET(String url) {

    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(url);

    int responseCode = 0;
    String responseHTML = null;

    try {
        responseCode = client.executeMethod(method);
        responseHTML = method.getResponseBodyAsString();
    } catch (Exception e) {
        // log me!
    } finally {
        method.releaseConnection();
    }

    return response;
}

String quote(String symbol) {
    String data = "";
    String HTML = HttpGET(YAHOO_FINANCE_QUOTE_URL + symbol);

    // BIG TODO: parse the HTML for whatever data you find interesting

    return data;
}

public static void main(String[] args) {
    YahooFinanceScraper y = new YahooFinanceScraper();
    String data = y.quote("FTSE");
}

static final String YAHOO_FINANCE_QUOTE_URL = "http://finance.yahoo.com/q?s=^";
}