qrtt1

Untitled

Jul 29th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.net.URL;
  5.  
  6. public class ShowData {
  7.  
  8. public void fetch(String stockNo) throws IOException {
  9. URL httpurl = new URL("http://tw.stock.yahoo.com/q/q?s=" + stockNo);
  10. BufferedReader br = new BufferedReader(new InputStreamReader(httpurl.openStream(), "Big5"));
  11. String result = "";
  12. String tmp;
  13. while ((tmp = br.readLine()) != null) {
  14. if (tmp.contains("href=\"/q/bc?s=" + stockNo + "\">")) {
  15. System.out.println(tmp.substring(tmp.indexOf(">") + 1, tmp.indexOf("<")));
  16. result = result + tmp.substring(tmp.indexOf(">") + 1, tmp.indexOf("<"));
  17. }
  18. if (tmp.contains("<td align=\"center\" bgcolor=\"#FFFfff\" nowrap><b>")) {
  19. System.out.println(tmp.substring(tmp.indexOf("b>") + 2, tmp.indexOf("</")));
  20. result = result + " " + tmp.substring(tmp.indexOf("b>") + 2, tmp.indexOf("</"));
  21. }
  22. }
  23. br.close();
  24. System.out.println(result);
  25. }
  26.  
  27. public static void main(String[] args) throws IOException {
  28. new ShowData().fetch("0050");
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment