Advertisement
nRikee

Random Games

Oct 23rd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.net.*;
  4. /**
  5.  * @author nrikee
  6.  * @version 24/10/2013
  7.  */
  8. public class parser
  9. {
  10.     public static void main(String[] args) throws Exception{    
  11.         String str = "http://steamcommunity.com/id/" + args[0] + "/games?tab=all&xml=1";
  12.         str = getContenidoHTML(str);
  13.        
  14.         String ori = "";
  15.         String fin = "";
  16.        
  17.         while ( str.indexOf("\n")!=-1 ){
  18.             ori = str.substring(0,str.indexOf("\n"));
  19.             str = str.substring(str.indexOf("\n")+1,str.length());
  20.             int x = ori.indexOf("name><![CDATA["),
  21.                 y = ori.indexOf("]]></name");
  22.             if (x==-1 || y==-1){
  23.                 continue; }
  24.             fin += ori.substring(x+14,y) + "\n";
  25.         }
  26.        
  27.         System.out.println(fin);
  28.     }
  29.    
  30.     private static String getContenidoHTML(String u) throws IOException {
  31.             URL url = new URL(u);
  32.             URLConnection uc = url.openConnection();
  33.             uc.connect();
  34.             //Creamos el objeto con el que vamos a leer
  35.             BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
  36.             String inputLine;
  37.             String contenido = "";
  38.             while ((inputLine = in.readLine()) != null) {
  39.                 contenido += inputLine + "\n";
  40.             }
  41.             in.close();
  42.             return contenido;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement