我正在使用Java Swing爲我的遊戲製作啓動程序。我需要一種將tumblr/wordpress feed添加到啓動器的方法。一個例子是「我的世界」發射器(如果你不知道它是什麼樣子,go to this link)。如何將tumblr源添加到java swing項目中
我也在想RSS可能是有用的,因爲我已經看到在提要和類似的東西上提到,所以如果有一個簡單的方法,那麼這也會有所幫助。
無論如何,我會如何做到這一點?
編輯:我將如何在Swing中使用jsoup?
我正在使用Java Swing爲我的遊戲製作啓動程序。我需要一種將tumblr/wordpress feed添加到啓動器的方法。一個例子是「我的世界」發射器(如果你不知道它是什麼樣子,go to this link)。如何將tumblr源添加到java swing項目中
我也在想RSS可能是有用的,因爲我已經看到在提要和類似的東西上提到,所以如果有一個簡單的方法,那麼這也會有所幫助。
無論如何,我會如何做到這一點?
編輯:我將如何在Swing中使用jsoup?
這裏是我已經習慣了從一個頁面
private static final String url = "website";
public void getLatestUpdate() throws IOException {
try {
URL addr = new URL(url);
URLConnection con = addr.openConnection();
ArrayList<String> data = new ArrayList<String>();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
Pattern p = Pattern.compile("<span itemprop=.*?</span>");
Pattern p2 = Pattern.compile(">.*?<");
Matcher m = p.matcher(inputLine);
Matcher m2;
while (m.find()) {
m2 = p2.matcher(m.group());
while (m2.find()) {
data.add(m2.group().replaceAll("<", "").replaceAll(">", "").replaceAll("&", "").replaceAll("#", "").replaceAll(";", "").replaceAll("3", "3"));
}
}
}
in.close();
addr = null;
con = null;
message("(" + data.get(3) + ")" + ", at " + data.get(4));
} catch (Exception e) {
System.out.println("Error getting data from website.");
e.printStackTrace();
}
}
解析數據只是解析頁面的源代碼,並顯示它,只要你喜歡一個例子。你可以使用正則表達式來解析你需要的必要數據。 – user
你知道我會怎麼做嗎? –
使用某種HTML解析器,例如[jsoup](http://jsoup.org/) – MadProgrammer