NoNameCracksInc

Jsoup parser

Jan 17th, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. import org.jsoup.*;
  2. import java.io.*;
  3. import org.jsoup.nodes.*;
  4.  
  5. public class Analyser
  6. {
  7.     public boolean connected=false;
  8.     public String full_line;
  9.     public String command;
  10.     public Document con;
  11.    
  12.     public static void main(String args[]) throws IOException
  13.     {
  14.         Analyser obj=new Analyser();
  15.         obj.core();
  16.     }
  17.    
  18.     public void core() throws IOException
  19.     {
  20.         BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
  21.  
  22.         connect();     
  23.         do
  24.         {
  25.             command=scan.readLine();
  26.             switches();
  27.         }
  28.         while(!command.equals(":quit"));
  29.     }
  30.    
  31.     public void connect() throws IOException
  32.     {
  33.         BufferedReader get=new BufferedReader(new InputStreamReader(System.in));
  34.        
  35.         do
  36.         {
  37.          full_line=get.readLine();
  38.          
  39.          if(full_line.contains(":connect"))
  40.          {
  41.              int length=full_line.length();
  42.              String website=full_line.substring(10,length);
  43.              con=Jsoup.connect("http://"+website).get();
  44.              connected=true;
  45.              System.out.println("connected.");
  46.              return;
  47.          }
  48.          else
  49.          {
  50.              System.out.println("Wrong syntax.Use command [:connect websitename].");
  51.          }
  52.         }
  53.         while(!full_line.contains(":connect"));
  54.     }
  55.    
  56.     public void switches() throws IOException
  57.     {
  58.         if(connected)
  59.         {
  60.             if(command.contains(":get"))
  61.             {
  62.                 if(command.contains("-n"))
  63.                 {
  64.                     System.out.println(con.nodeName());
  65.                 }  
  66.                
  67.                 if(command.contains("-t"))
  68.                 {
  69.                     System.out.println(con.tagName());
  70.                 }
  71.                
  72.                 if(command.contains("-s"))
  73.                 {
  74.                     System.out.println(con.html());
  75.                 }
  76.                
  77.                 if(command.contains("-txt"))
  78.                 {
  79.                     System.out.println(con.text());
  80.                 }
  81.                 if(command.contains("-h"))
  82.                 {
  83.                     System.out.println(con.hashCode());
  84.                 }
  85.             }
  86.             if(command.contains(":reload"))
  87.             {
  88.                 connect();
  89.                 return;
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment