如何将网站结果(例如https://blockchain.info/de/q/24hrprice)转换为字符串/整数?我是否必须从网站上阅读源代码?
我正在使用Android Studio进行开发。
答案 0 :(得分:0)
BufferedReader in = null;
try {
String urlStr = "https://blockchain.info/de/q/24hrprice";
URL url = new URL(urlStr);
URLConnection con = url.openConnection();
in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String input;
while ((input = in.readLine()) != null) {
System.out.println(input); //you can parse input as Integer or Double now
}
} catch (MalformedURLException ex) {
System.err.println(ex);
} catch (IOException ex) {
System.err.println(ex);
} finally {
try {
in.close();
} catch (Exception ex) {
System.err.println(ex);
}
}