Capturar datos de Google
Tiene un API, que te devuelve la informacion en JSON para calculos de divisas:
http://www.google.com/ig/calculator?hl= … D%3D%3FCAD
No se cada cuanto lo actualizaran.
Como utilizamos esto en Java?
Code: Select allpackage com.caplin.datasrc.ret.ct;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import com.google.gson.Gson;
public class SeedGenerator
{
static class Result
{
private String lhs;
private String rhs;
public String getLhs()
{
return lhs;
}
public String getRhs()
{
return rhs;
}
public void setLhs(String lhs)
{
this.lhs = lhs;
}
public void setRhs(String rhs)
{
this.rhs = rhs;
}
}
public static void main(String[] args) throws Exception
{
String google = "http://www.google.com/ig/calculator?hl=en&q=";
String baseCurrency = "GBP";
String termCurrency = "AUD";
String charset = "UTF-8";
URL url = new URL(google + baseCurrency + "%3D%3F" + termCurrency);
Reader reader = new InputStreamReader(url.openStream(), charset);
Result result = new Gson().fromJson(reader, Result.class);
// Get the value without the term currency.
String amount = result.getRhs().split("\s+")[0];
System.out.println(amount);
}
}