Skip to content

Instantly share code, notes, and snippets.

@damiancastelao
Created April 13, 2018 13:16
Show Gist options
  • Save damiancastelao/cbd73526b7957f144438f00349fbd8ba to your computer and use it in GitHub Desktop.
Save damiancastelao/cbd73526b7957f144438f00349fbd8ba to your computer and use it in GitHub Desktop.
Obtener datos pagina web
package com.ejemplo.dam;
import java.io.IOException;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class ElTiempo {
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
// setup URL
Connection miconnect = Jsoup.connect("https://weather.com/es-ES/tiempo/hoy/l/SPXX0084:1:SP");
// slow connection
miconnect.timeout(2000);
// method get, execute
Document doc = miconnect.get();
// check status 200 - OK, response web server
if (miconnect.response().statusCode() == 200) {
System.out.println(doc.title());
System.out.println(doc.select(".today_nowcard-phrase").first().text());
System.out.println(doc.select(".today_nowcard-temp").first().text());
} else {
System.out.println("Error:"+miconnect.response().statusCode());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment