我在一家网站上获取了数据,并且它被展示在下面的图片中:
这个网站提供了一些参数的值,这些值每隔一段时间就会更新。现在,我想在 Android 应用程序中根据列名和行号检索这些数据,我知道如何打开 http 连接。但不幸的是,我不知道该从哪里开始以及如何读取图片中提供的数据。
除非您有特殊的数据源可供使用,否则您必须手动读取网站内容并进行处理。以下是来自Java教程的链接,介绍如何从URL连接中读取内容。
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
编辑:
如果你在代理后面,你还应该设置这些系统属性(为适当的值):
System.setProperty("http.proxyHost", "3.182.12.1");
System.setProperty("http.proxyPort", "1111");
Scanner s;
while ((inputLine = in.readLine()) != null)
{
s = new Scanner(input).useDelimiter(" ");
//Then readthe Values like
value = s.next()); // add all values in a list or array
}
s.close();