我有一些 java 代码可以从我选择的网站打印出 html。我希望它只打印出 HTML 代码中的特定日期,如下所示:
<tr class="bgWhite">
<td align="center" width="50"><nobr>GD </nobr></td>
<td align="center">Q3 2012</td>
<td align="left" width="*">Q3 2012 General Dynamics Earnings Release</td>
<td align="center">$ 1.83 </td>
<td align="center">n/a </td>
<td align="center">$ 1.83 </td>
<td align="center"><nobr>24-Oct-12</nobr></td>
</tr>
<tr class="bgWhite">
<td align="center" width="50"><nobr>GD </nobr></td>
<td align="center">Q2 2012</td>
<td align="left" width="*">Q2 2012 General Dynamics Earnings Release</td>
<td align="center">$ 1.75 </td>
<td align="center">n/a </td>
<td align="center">$ 1.79 </td>
<td align="center"><nobr>25-Jul-12 BMO</nobr></td>
</tr>
所以我只希望它打印出来:24-Oct-12 25-Jul-12
我怎么做?
这是我拥有的代码:
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.earnings.com/company.asp?client=cb&ticker=gd");
urlConn = url.openConnection();
inStream = new InputStreamReader(
urlConn.getInputStream());
buff= new BufferedReader(inStream);
// Read and print the lines from index.html
while (true){
nextLine =buff.readLine();
if (nextLine !=null){
System.out.println(nextLine);
}
else{
break;
}
}
} 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() );
}