Skip to content

Instantly share code, notes, and snippets.

@bobbyjam99-zz
Created January 23, 2015 03:43
Show Gist options
  • Save bobbyjam99-zz/9da921e7059254458f95 to your computer and use it in GitHub Desktop.
Save bobbyjam99-zz/9da921e7059254458f95 to your computer and use it in GitHub Desktop.
今日の傘指数取得
package org.bobbyjam99;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import us.codecraft.xsoup.Xsoup;
public class UmbrellaIndex {
public static void main(String[] args) throws Exception {
// 東京都東京地方(東京)の傘指数 を 日本気象協会 tenki.jp から取得
Document doc = getUmbrellaIndexDocument();
String location = getLocation(doc);
String date = getDate(doc);
String umbrellaIndex = getUmblerllaIndex(doc);
String comment = getComment(doc);
System.out.println(location + " " + date + " " + umbrellaIndex + " "
+ comment);
}
private static Document getUmbrellaIndexDocument() throws Exception {
return Jsoup.connect(
"http://www.tenki.jp/indexes/umbrella/3/16/4410.html").get();
}
private static String getLocation(Document doc) {
return Xsoup
.compile("//*[@id=\"bd-main\"]/div[1]/div[1]/div/h1/text()")
.evaluate(doc).get();
}
private static String getDate(Document doc) {
return Xsoup.compile("//*[@id=\"exponentLargeLeft\"]/dt/strong/text()")
.evaluate(doc).get();
}
private static String getUmblerllaIndex(Document doc) {
return Xsoup.compile("//*[@id=\"exponentLargeLeft\"]/dd/dl/dd/text()")
.evaluate(doc).get();
}
private static String getComment(Document doc) {
return Xsoup.compile("//*[@id=\"exponentLargeLeft\"]/dd/p[2]/text()")
.evaluate(doc).get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment