eclipse用java解析网页
我想把这个网页上的实时速率解析成我的java程序,也就是说,我想把每秒刷新的网页上的数据不断地流到我的程序中
如果可能的话,我想使用标准java库来实现这一点。我知道像jsoup这样的插件,可能还有其他插件,但我不想下载和安装这些插件,因为我正在使用的计算机的硬盘位于加利福尼亚州,除了几个核心程序外,其他所有程序都会在每晚系统重新启动时被删除,eclipse就是其中之一
因此,如果有人知道标准eclipse下载中有一个包可以做到这一点,请告诉我!谢谢
好吧,我让它工作了,但它看起来很慢。例如,数据会一秒一秒地改变,即使我也在一秒一秒地刷新我从中读取的网页(我使用了thread.sleep(1000)),然后得到一个新的网页实例,但它大约每分钟只更新一次。有什么好处
以下是我的代码(我使用了你上面发布的内容作为我的url阅读器):
public String getPage(String urlString){
String result = "";
//Access the page
try {
// Create a URL for the desired page
URL url = new URL(urlString);
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
result += str;
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return result;
}
public static void main(String[]args){
int i =0;
Reading r = new Reading();
while(true){
try{Thread.sleep(1000);}catch(Exception e){}
String page = new String(r.getPage("http://www.fxstreet.com/rates-charts/forex-rates/"));
int index = page.indexOf("last_3212166");
//System.out.println(i+page);
i++;
System.out.println(i+"GBP/USD: "+page.substring(index+14,index+20));
}
共 (0) 个答案