Saltar al contenido
Buscando la Libertad
Dejar de depender de una nómina: montar algo, comprar algo o vivir de lo invertido

Capturar datos de Google

· Dalamar

Dalamar · 20 de noviembre de 2012

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.

Dalamar · 20 de noviembre de 2012

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);
   }
}