我想解析這個字符串出網站和識別並存儲在變量的顏色(可以說,如果其綠色分配值0,或者如果其他1)。parsin文本out.html頁面java
<tr><td class="mapbuttons" align=right>
<a href="http://www...."><font color=green>TEXT <font color=#ff8000>(2)</font>3/14</font></a>
我發現這個演示代碼:
import java.net.*;
import java.io.*;
public class WebSiteReader {
public static void main(String args[]){
String nextLine;
URL url = null;
URLConnection urlConn = null;
InputStreamReader inStream = null;
BufferedReader buff = null;
try{
// Create the URL obect that points
// at the default file index.html
url = new URL("http://www.yahoo.com");
urlConn = url.openConnection();
inStream = new InputStreamReader(
urlConn.getInputStream());
buff= new BufferedReader(inStream);
// get the values I want here
} catch(MalformedURLException e){
System.out.println("Please check the URL:" +
e.toString());
} catch(IOException e1){
System.out.println("Can't read from the Internet: "+
e1.toString());
}
}
}
1)它是correnct?我的意思是我希望將代碼替換爲我想要的代碼,對吧? 2)你可以幫助我的代碼,因爲我是新來的Java和如何「玩」與文本?
如果你要玩,使用String和模式類。這些正則表達式會變得很大而且很難看,但是它們能夠工作 - 這只是一個解決方案:) – wuppi 2012-04-19 11:11:29